Page
Library
Module
Module type
Parameter
Class
Class type
Source
MwtSourceThis module provides a way to call a function from Lwt and have that function in a separate OCaml preemptive thread.
Pools of threads which may be delegated to from an Lwt application. Each thread in the pool carries its own local state which is passed to any function running within a pool's thread.
Preemptive thread pool carrying some local state type
make ~init ~at_exit num_threads creates a new pool of num_threads preemptive threads. If no special per-thread state is required you can pass noop to init and at_exit. The returned promise will resolve once all num_threads calls to init have completed. If any instance of init raises an exception then the resulting promise will resolve to the same exception.
noop may be passed to the init and at_exit parameters of make when no special per-thread initialization or cleanup is required. noop is fun () -> ().
run pool f will run f state in one of the preemptive threads in pool, where state carries the state of the thread f runs under. If there is a thread available in pool then the call will block until f completes. If no thread is available from pool then the call to f will be queued until a thread in pool is available.
f may use run_in_main to run code in a program's Lwt context.
close pool immediately marks pool as closed, quits all idle threads in the pool and blocks until all in-use threads have terminated. Any further uses of pool will raise Invalid_argument.
close_async pool marks pool as closed and sends a "quit" signal to all idle threads. Any threads currently in use will quit once they are done with their current task. This function does not block.