diff --git a/moonpool-lwt/Moonpool_lwt/index.html b/moonpool-lwt/Moonpool_lwt/index.html index dea9daa8..73fb0bc2 100644 --- a/moonpool-lwt/Moonpool_lwt/index.html +++ b/moonpool-lwt/Moonpool_lwt/index.html @@ -1,2 +1,2 @@ -
Moonpool_lwtLwt_engine-based event loop for Moonpool.
In what follows, we mean by "lwt thread" the thread running Lwt_main.run (so, the thread where the Lwt event loop and all Lwt callbacks execute).
module Fiber = Moonpool_fib.Fibermodule FLS = Moonpool_fib.Flsval fut_of_lwt : 'a Lwt.t -> 'a Moonpool.Fut.tfut_of_lwt lwt_fut makes a thread-safe moonpool future that completes when lwt_fut does. This must be run from within the Lwt thread.
val lwt_of_fut : 'a Moonpool.Fut.t -> 'a Lwt.tlwt_of_fut fut makes a lwt future that completes when fut does. This must be called from the Lwt thread, and the result must always be used only from inside the Lwt thread.
val await_lwt : 'a Lwt.t -> 'aawait_lwt fut awaits a Lwt future from inside a task running on a moonpool runner. This must be run from within a Moonpool runner so that the await-ing effect is handled.
val run_in_lwt : (unit -> 'a Lwt.t) -> 'a Moonpool.Fut.trun_in_lwt f runs f() from within the Lwt thread and returns a thread-safe future. This can be run from anywhere.
val run_in_lwt_and_await : (unit -> 'a Lwt.t) -> 'arun_in_lwt_and_await f runs f in the Lwt thread, and awaits its result. Must be run from inside a moonpool runner so that the await-in effect is handled.
This is similar to Moonpool.await @@ run_in_lwt f.
val get_runner : unit -> Moonpool.Runner.tReturns the runner from within which this is called. Must be run from within a fiber.
module IO : sig ... endIO using the Lwt event loop.
module IO_in : sig ... endInput channel
module IO_out : sig ... endOutput channel
module TCP_server : sig ... endmodule TCP_client : sig ... endval detach_in_runner : runner:Moonpool.Runner.t -> (unit -> 'a) -> 'a Lwt.tdetach_in_runner ~runner f runs f in the given moonpool runner, and returns a lwt future. This must be run from within the thread running Lwt_main.
val main_with_runner : runner:Moonpool.Runner.t -> (unit -> 'a) -> 'amain_with_runner ~runner f starts a Lwt-based event loop and runs f() inside a fiber in runner.
Like main_with_runner but with a default choice of runner.
Moonpool_lwtLwt_engine-based event loop for Moonpool.
In what follows, we mean by "lwt thread" the thread running Lwt_main.run (so, the thread where the Lwt event loop and all Lwt callbacks execute).
NOTE: this is experimental and might change in future versions.
module Fiber = Moonpool_fib.Fibermodule FLS = Moonpool_fib.Flsval fut_of_lwt : 'a Lwt.t -> 'a Moonpool.Fut.tfut_of_lwt lwt_fut makes a thread-safe moonpool future that completes when lwt_fut does. This must be run from within the Lwt thread.
val lwt_of_fut : 'a Moonpool.Fut.t -> 'a Lwt.tlwt_of_fut fut makes a lwt future that completes when fut does. This must be called from the Lwt thread, and the result must always be used only from inside the Lwt thread.
val await_lwt : 'a Lwt.t -> 'aawait_lwt fut awaits a Lwt future from inside a task running on a moonpool runner. This must be run from within a Moonpool runner so that the await-ing effect is handled.
val run_in_lwt : (unit -> 'a Lwt.t) -> 'a Moonpool.Fut.trun_in_lwt f runs f() from within the Lwt thread and returns a thread-safe future. This can be run from anywhere.
val run_in_lwt_and_await : (unit -> 'a Lwt.t) -> 'arun_in_lwt_and_await f runs f in the Lwt thread, and awaits its result. Must be run from inside a moonpool runner so that the await-in effect is handled.
This is similar to Moonpool.await @@ run_in_lwt f.
val get_runner : unit -> Moonpool.Runner.tReturns the runner from within which this is called. Must be run from within a fiber.
module IO : sig ... endIO using the Lwt event loop.
module IO_in : sig ... endInput channel
module IO_out : sig ... endOutput channel
module TCP_server : sig ... endmodule TCP_client : sig ... endval detach_in_runner : runner:Moonpool.Runner.t -> (unit -> 'a) -> 'a Lwt.tdetach_in_runner ~runner f runs f in the given moonpool runner, and returns a lwt future. This must be run from within the thread running Lwt_main.
val main_with_runner : runner:Moonpool.Runner.t -> (unit -> 'a) -> 'amain_with_runner ~runner f starts a Lwt-based event loop and runs f() inside a fiber in runner.
Like main_with_runner but with a default choice of runner.
Moonpool.Background_threadA simple runner with a single background thread.
Because this is guaranteed to have a single worker thread, tasks scheduled in this runner always run asynchronously but in a sequential fashion.
This is similar to Fifo_pool with exactly one thread.
include module type of RunnerA runner.
If a runner is no longer needed, shutdown can be used to signal all worker threads in it to stop (after they finish their work), and wait for them to stop.
The threads are distributed across a fixed domain pool (whose size is determined by Domain.recommended_domain_count on OCaml 5, and simple the single runtime on OCaml 4).
val size : t -> intNumber of threads/workers.
val num_tasks : t -> intCurrent number of tasks. This is at best a snapshot, useful for metrics and debugging.
val shutdown : t -> unitShutdown the runner and wait for it to terminate. Idempotent.
val shutdown_without_waiting : t -> unitShutdown the pool, and do not wait for it to terminate. Idempotent.
val run_async : ?ls:Task_local_storage.t -> t -> task -> unitrun_async pool f schedules f for later execution on the runner in one of the threads. f() will run on one of the runner's worker threads/domains.
val run_wait_block : ?ls:Task_local_storage.t -> t -> (unit -> 'a) -> 'arun_wait_block pool f schedules f for later execution on the pool, like run_async. It then blocks the current thread until f() is done executing, and returns its result. If f() raises an exception, then run_wait_block pool f will raise it as well.
NOTE be careful with deadlocks (see notes in Fut.wait_block about the required discipline to avoid deadlocks).
val dummy : tRunner that fails when scheduling tasks on it. Calling run_async on it will raise Failure.
module For_runner_implementors : sig ... endThis module is specifically intended for users who implement their own runners. Regular users of Moonpool should not need to look at it.
val get_current_runner : unit -> t optionAccess the current runner. This returns Some r if the call happens on a thread that belongs in a runner.
val get_current_storage : unit -> Task_local_storage.t optionget_current_storage runner gets the local storage for the currently running task.
type ('a, 'b) create_args =
+Background_thread (moonpool.Moonpool.Background_thread) Module Moonpool.Background_thread
A simple runner with a single background thread.
Because this is guaranteed to have a single worker thread, tasks scheduled in this runner always run asynchronously but in a sequential fashion.
This is similar to Fifo_pool with exactly one thread.
include module type of Runner
A runner.
If a runner is no longer needed, shutdown can be used to signal all worker threads in it to stop (after they finish their work), and wait for them to stop.
The threads are distributed across a fixed domain pool (whose size is determined by Domain.recommended_domain_count on OCaml 5, and simple the single runtime on OCaml 4).
val size : t -> intNumber of threads/workers.
val num_tasks : t -> intCurrent number of tasks. This is at best a snapshot, useful for metrics and debugging.
val shutdown : t -> unitShutdown the runner and wait for it to terminate. Idempotent.
val shutdown_without_waiting : t -> unitShutdown the pool, and do not wait for it to terminate. Idempotent.
val run_async : ?ls:Task_local_storage.t -> t -> task -> unitrun_async pool f schedules f for later execution on the runner in one of the threads. f() will run on one of the runner's worker threads/domains.
val run_wait_block : ?ls:Task_local_storage.t -> t -> (unit -> 'a) -> 'arun_wait_block pool f schedules f for later execution on the pool, like run_async. It then blocks the current thread until f() is done executing, and returns its result. If f() raises an exception, then run_wait_block pool f will raise it as well.
NOTE be careful with deadlocks (see notes in Fut.wait_block about the required discipline to avoid deadlocks).
val dummy : tRunner that fails when scheduling tasks on it. Calling run_async on it will raise Failure.
Implementing runners
module For_runner_implementors : sig ... endThis module is specifically intended for users who implement their own runners. Regular users of Moonpool should not need to look at it.
val get_current_runner : unit -> t optionAccess the current runner. This returns Some r if the call happens on a thread that belongs in a runner.
val get_current_storage : unit -> Task_local_storage.t optionget_current_storage runner gets the local storage for the currently running task.
type ('a, 'b) create_args =
?on_init_thread:(dom_id:int -> t_id:int -> unit -> unit) ->
?on_exit_thread:(dom_id:int -> t_id:int -> unit -> unit) ->
?on_exn:(exn -> Stdlib.Printexc.raw_backtrace -> unit) ->
diff --git a/moonpool/Moonpool/Exn_bt/index.html b/moonpool/Moonpool/Exn_bt/index.html
index da518584..15f1dd6f 100644
--- a/moonpool/Moonpool/Exn_bt/index.html
+++ b/moonpool/Moonpool/Exn_bt/index.html
@@ -1,2 +1,2 @@
-Exn_bt (moonpool.Moonpool.Exn_bt) Module Moonpool.Exn_bt
Exception with backtrace.
type t = exn * Stdlib.Printexc.raw_backtraceAn exception bundled with a backtrace
val exn : t -> exnval bt : t -> Stdlib.Printexc.raw_backtraceval make : exn -> Stdlib.Printexc.raw_backtrace -> tTrivial builder
val get : exn -> tget exn is make exn (get_raw_backtrace ())
val get_callstack : int -> exn -> tval raise : t -> 'aRaise the exception with its save backtrace
val show : t -> stringSimple printing
+Exn_bt (moonpool.Moonpool.Exn_bt) Module Moonpool.Exn_bt
Exception with backtrace.
type t = exn * Stdlib.Printexc.raw_backtraceAn exception bundled with a backtrace
val exn : t -> exnval bt : t -> Stdlib.Printexc.raw_backtraceval make : exn -> Stdlib.Printexc.raw_backtrace -> tTrivial builder
val get : exn -> tget exn is make exn (get_raw_backtrace ())
val get_callstack : int -> exn -> tval raise : t -> 'aRaise the exception with its save backtrace
val show : t -> stringSimple printing
diff --git a/moonpool/Moonpool/Fifo_pool/index.html b/moonpool/Moonpool/Fifo_pool/index.html
index 3c278b1c..bc5bf6e2 100644
--- a/moonpool/Moonpool/Fifo_pool/index.html
+++ b/moonpool/Moonpool/Fifo_pool/index.html
@@ -1,9 +1,9 @@
-Fifo_pool (moonpool.Moonpool.Fifo_pool) Module Moonpool.Fifo_pool
A simple thread pool in FIFO order.
FIFO: first-in, first-out. Basically tasks are put into a queue, and worker threads pull them out of the queue at the other end.
Since this uses a single blocking queue to manage tasks, it's very simple and reliable. The number of worker threads is fixed, but they are spread over several domains to enable parallelism.
This can be useful for latency-sensitive applications (e.g. as a pool of workers for network servers). Work-stealing pools might have higher throughput but they're very unfair to some tasks; by contrast, here, older tasks have priority over younger tasks.
include module type of Runner
A runner.
If a runner is no longer needed, shutdown can be used to signal all worker threads in it to stop (after they finish their work), and wait for them to stop.
The threads are distributed across a fixed domain pool (whose size is determined by Domain.recommended_domain_count on OCaml 5, and simple the single runtime on OCaml 4).
val size : t -> intNumber of threads/workers.
val num_tasks : t -> intCurrent number of tasks. This is at best a snapshot, useful for metrics and debugging.
val shutdown : t -> unitShutdown the runner and wait for it to terminate. Idempotent.
val shutdown_without_waiting : t -> unitShutdown the pool, and do not wait for it to terminate. Idempotent.
val run_async : ?ls:Task_local_storage.t -> t -> task -> unitrun_async pool f schedules f for later execution on the runner in one of the threads. f() will run on one of the runner's worker threads/domains.
val run_wait_block : ?ls:Task_local_storage.t -> t -> (unit -> 'a) -> 'arun_wait_block pool f schedules f for later execution on the pool, like run_async. It then blocks the current thread until f() is done executing, and returns its result. If f() raises an exception, then run_wait_block pool f will raise it as well.
NOTE be careful with deadlocks (see notes in Fut.wait_block about the required discipline to avoid deadlocks).
val dummy : tRunner that fails when scheduling tasks on it. Calling run_async on it will raise Failure.
Implementing runners
module For_runner_implementors : sig ... endThis module is specifically intended for users who implement their own runners. Regular users of Moonpool should not need to look at it.
val get_current_runner : unit -> t optionAccess the current runner. This returns Some r if the call happens on a thread that belongs in a runner.
val get_current_storage : unit -> Task_local_storage.t optionget_current_storage runner gets the local storage for the currently running task.
type ('a, 'b) create_args =
+Fifo_pool (moonpool.Moonpool.Fifo_pool) Module Moonpool.Fifo_pool
A simple thread pool in FIFO order.
FIFO: first-in, first-out. Basically tasks are put into a queue, and worker threads pull them out of the queue at the other end.
Since this uses a single blocking queue to manage tasks, it's very simple and reliable. The number of worker threads is fixed, but they are spread over several domains to enable parallelism.
This can be useful for latency-sensitive applications (e.g. as a pool of workers for network servers). Work-stealing pools might have higher throughput but they're very unfair to some tasks; by contrast, here, older tasks have priority over younger tasks.
include module type of Runner
A runner.
If a runner is no longer needed, shutdown can be used to signal all worker threads in it to stop (after they finish their work), and wait for them to stop.
The threads are distributed across a fixed domain pool (whose size is determined by Domain.recommended_domain_count on OCaml 5, and simple the single runtime on OCaml 4).
val size : t -> intNumber of threads/workers.
val num_tasks : t -> intCurrent number of tasks. This is at best a snapshot, useful for metrics and debugging.
val shutdown : t -> unitShutdown the runner and wait for it to terminate. Idempotent.
val shutdown_without_waiting : t -> unitShutdown the pool, and do not wait for it to terminate. Idempotent.
val run_async : ?ls:Task_local_storage.t -> t -> task -> unitrun_async pool f schedules f for later execution on the runner in one of the threads. f() will run on one of the runner's worker threads/domains.
val run_wait_block : ?ls:Task_local_storage.t -> t -> (unit -> 'a) -> 'arun_wait_block pool f schedules f for later execution on the pool, like run_async. It then blocks the current thread until f() is done executing, and returns its result. If f() raises an exception, then run_wait_block pool f will raise it as well.
NOTE be careful with deadlocks (see notes in Fut.wait_block about the required discipline to avoid deadlocks).
val dummy : tRunner that fails when scheduling tasks on it. Calling run_async on it will raise Failure.
Implementing runners
module For_runner_implementors : sig ... endThis module is specifically intended for users who implement their own runners. Regular users of Moonpool should not need to look at it.
val get_current_runner : unit -> t optionAccess the current runner. This returns Some r if the call happens on a thread that belongs in a runner.
val get_current_storage : unit -> Task_local_storage.t optionget_current_storage runner gets the local storage for the currently running task.
type ('a, 'b) create_args =
?on_init_thread:(dom_id:int -> t_id:int -> unit -> unit) ->
?on_exit_thread:(dom_id:int -> t_id:int -> unit -> unit) ->
?on_exn:(exn -> Stdlib.Printexc.raw_backtrace -> unit) ->
?around_task:((t -> 'b) * (t -> 'b -> unit)) ->
?num_threads:int ->
?name:string ->
- 'aval create : (unit -> t, _) create_argscreate () makes a new thread pool.
val with_ : (unit -> (t -> 'a) -> 'a, _) create_args
+ 'aval create : (unit -> t, _) create_argscreate () makes a new thread pool.
val with_ : (unit -> (t -> 'a) -> 'a, _) create_args
diff --git a/moonpool/Moonpool/Fut/index.html b/moonpool/Moonpool/Fut/index.html
index 448c2088..54e7f1db 100644
--- a/moonpool/Moonpool/Fut/index.html
+++ b/moonpool/Moonpool/Fut/index.html
@@ -1,2 +1,2 @@
-Fut (moonpool.Moonpool.Fut) Module Moonpool.Fut
Futures.
A future of type 'a t represents the result of a computation that will yield a value of type 'a.
Typically, the computation is running on a thread pool Runner.t and will proceed on some worker. Once set, a future cannot change. It either succeeds (storing a Ok x with x: 'a), or fail (storing a Error (exn, bt) with an exception and the corresponding backtrace).
Combinators such as map and join_array can be used to produce futures from other futures (in a monadic way). Some combinators take a on argument to specify a runner on which the intermediate computation takes place; for example map ~on:pool ~f fut maps the value in fut using function f, applicatively; the call to f happens on the runner pool (once fut resolves successfully with a value).
on_result fut f registers f to be called in the future when fut is set ; or calls f immediately if fut is already set.
Fullfill the promise, setting the future at the same time.
Fullfill the promise, setting the future at the same time. Does nothing if the promise is already fulfilled.
val return : 'a -> 'a tAlready settled future, with a result
val fail : exn -> Stdlib.Printexc.raw_backtrace -> _ tAlready settled future, with a failure
val is_resolved : _ t -> boolis_resolved fut is true iff fut is resolved.
peek fut returns Some r if fut is currently resolved with r, and None if fut is not resolved yet.
get_or_fail fut obtains the result from fut if it's fulfilled (i.e. if peek fut returns Some res, get_or_fail fut returns res).
val get_or_fail_exn : 'a t -> 'aget_or_fail_exn fut obtains the result from fut if it's fulfilled, like get_or_fail. If the result is an Error _, the exception inside is re-raised.
val is_done : _ t -> boolIs the future resolved? This is the same as peek fut |> Option.is_some.
val is_success : _ t -> boolChecks if the future is resolved with Ok _ as a result.
val is_failed : _ t -> boolChecks if the future is resolved with Error _ as a result.
val raise_if_failed : _ t -> unitraise_if_failed fut raises e if fut failed with e.
Combinators
spaw ~on f runs f() on the given runner on, and return a future that will hold its result.
val spawn_on_current_runner : (unit -> 'a) -> 'a tThis must be run from inside a runner, and schedules the new task on it as well.
See Runner.get_current_runner to see how the runner is found.
reify_error fut turns a failing future into a non-failing one that contain Error (exn, bt). A non-failing future returning x is turned into Ok x
map ?on ~f fut returns a new future fut2 that resolves with f x if fut resolved with x; and fails with e if fut fails with e or f x raises e.
bind ?on ~f fut returns a new future fut2 that resolves like the future f x if fut resolved with x; and fails with e if fut fails with e or f x raises e.
bind_reify_error ?on ~f fut returns a new future fut2 that resolves like the future f (Ok x) if fut resolved with x; and resolves like the future f (Error (exn, bt)) if fut fails with exn and backtrace bt.
both a b succeeds with x, y if a succeeds with x and b succeeds with y, or fails if any of them fails.
choose a b succeeds Left x or Right y if a succeeds with x or b succeeds with y, or fails if both of them fails. If they both succeed, it is not specified which result is used.
choose_same a b succeeds with the value of one of a or b if they succeed, or fails if both fail. If they both succeed, it is not specified which result is used.
Wait for all the futures in the array. Fails if any future fails.
Wait for all the futures in the list. Fails if any future fails.
module Advanced : sig ... endmap_list ~f l is like join_list @@ List.map f l.
wait_array arr waits for all futures in arr to resolve. It discards the individual results of futures in arr. It fails if any future fails.
wait_list l waits for all futures in l to resolve. It discards the individual results of futures in l. It fails if any future fails.
for_ ~on n f runs f 0, f 1, …, f (n-1) on the runner, and returns a future that resolves when all the tasks have resolved, or fails as soon as one task has failed.
for_array ~on arr f runs f 0 arr.(0), …, f (n-1) arr.(n-1) in the runner (where n = Array.length arr), and returns a future that resolves when all the tasks are done, or fails if any of them fails.
for_list ~on l f is like for_array ~on (Array.of_list l) f.
Await
NOTE This is only available on OCaml 5.
val await : 'a t -> 'aawait fut suspends the current tasks until fut is fulfilled, then resumes the task on this same runner (but possibly on a different thread/domain).
This must only be run from inside the runner itself. The runner must support Suspend_. NOTE: only on OCaml 5.x
Blocking
wait_block fut blocks the current thread until fut is resolved, and returns its value.
NOTE: A word of warning: this will monopolize the calling thread until the future resolves. This can also easily cause deadlocks, if enough threads in a pool call wait_block on futures running on the same pool or a pool depending on it.
A good rule to avoid deadlocks is to run this from outside of any pool, or to have an acyclic order between pools where wait_block is only called from a pool on futures evaluated in a pool that comes lower in the hierarchy. If this rule is broken, it is possible for all threads in a pool to wait for futures that can only make progress on these same threads, hence the deadlock.
val wait_block_exn : 'a t -> 'aSame as wait_block but re-raises the exception if the future failed.
Infix operators
These combinators run on either the current pool (if present), or on the same thread that just fulfilled the previous future if not.
They were previously present as module Infix_local and val infix, but are now simplified.
module Infix : sig ... endmodule Infix_local = Infix
+Fut (moonpool.Moonpool.Fut) Module Moonpool.Fut
Futures.
A future of type 'a t represents the result of a computation that will yield a value of type 'a.
Typically, the computation is running on a thread pool Runner.t and will proceed on some worker. Once set, a future cannot change. It either succeeds (storing a Ok x with x: 'a), or fail (storing a Error (exn, bt) with an exception and the corresponding backtrace).
Combinators such as map and join_array can be used to produce futures from other futures (in a monadic way). Some combinators take a on argument to specify a runner on which the intermediate computation takes place; for example map ~on:pool ~f fut maps the value in fut using function f, applicatively; the call to f happens on the runner pool (once fut resolves successfully with a value).
on_result fut f registers f to be called in the future when fut is set ; or calls f immediately if fut is already set.
Fullfill the promise, setting the future at the same time.
Fullfill the promise, setting the future at the same time. Does nothing if the promise is already fulfilled.
val return : 'a -> 'a tAlready settled future, with a result
val fail : exn -> Stdlib.Printexc.raw_backtrace -> _ tAlready settled future, with a failure
val is_resolved : _ t -> boolis_resolved fut is true iff fut is resolved.
peek fut returns Some r if fut is currently resolved with r, and None if fut is not resolved yet.
get_or_fail fut obtains the result from fut if it's fulfilled (i.e. if peek fut returns Some res, get_or_fail fut returns res).
val get_or_fail_exn : 'a t -> 'aget_or_fail_exn fut obtains the result from fut if it's fulfilled, like get_or_fail. If the result is an Error _, the exception inside is re-raised.
val is_done : _ t -> boolIs the future resolved? This is the same as peek fut |> Option.is_some.
val is_success : _ t -> boolChecks if the future is resolved with Ok _ as a result.
val is_failed : _ t -> boolChecks if the future is resolved with Error _ as a result.
val raise_if_failed : _ t -> unitraise_if_failed fut raises e if fut failed with e.
Combinators
spaw ~on f runs f() on the given runner on, and return a future that will hold its result.
val spawn_on_current_runner : (unit -> 'a) -> 'a tThis must be run from inside a runner, and schedules the new task on it as well.
See Runner.get_current_runner to see how the runner is found.
reify_error fut turns a failing future into a non-failing one that contain Error (exn, bt). A non-failing future returning x is turned into Ok x
map ?on ~f fut returns a new future fut2 that resolves with f x if fut resolved with x; and fails with e if fut fails with e or f x raises e.
bind ?on ~f fut returns a new future fut2 that resolves like the future f x if fut resolved with x; and fails with e if fut fails with e or f x raises e.
bind_reify_error ?on ~f fut returns a new future fut2 that resolves like the future f (Ok x) if fut resolved with x; and resolves like the future f (Error (exn, bt)) if fut fails with exn and backtrace bt.
both a b succeeds with x, y if a succeeds with x and b succeeds with y, or fails if any of them fails.
choose a b succeeds Left x or Right y if a succeeds with x or b succeeds with y, or fails if both of them fails. If they both succeed, it is not specified which result is used.
choose_same a b succeeds with the value of one of a or b if they succeed, or fails if both fail. If they both succeed, it is not specified which result is used.
Wait for all the futures in the array. Fails if any future fails.
Wait for all the futures in the list. Fails if any future fails.
module Advanced : sig ... endmap_list ~f l is like join_list @@ List.map f l.
wait_array arr waits for all futures in arr to resolve. It discards the individual results of futures in arr. It fails if any future fails.
wait_list l waits for all futures in l to resolve. It discards the individual results of futures in l. It fails if any future fails.
for_ ~on n f runs f 0, f 1, …, f (n-1) on the runner, and returns a future that resolves when all the tasks have resolved, or fails as soon as one task has failed.
for_array ~on arr f runs f 0 arr.(0), …, f (n-1) arr.(n-1) in the runner (where n = Array.length arr), and returns a future that resolves when all the tasks are done, or fails if any of them fails.
for_list ~on l f is like for_array ~on (Array.of_list l) f.
Await
NOTE This is only available on OCaml 5.
val await : 'a t -> 'aawait fut suspends the current tasks until fut is fulfilled, then resumes the task on this same runner (but possibly on a different thread/domain).
This must only be run from inside the runner itself. The runner must support Suspend_. NOTE: only on OCaml 5.x
Blocking
wait_block fut blocks the current thread until fut is resolved, and returns its value.
NOTE: A word of warning: this will monopolize the calling thread until the future resolves. This can also easily cause deadlocks, if enough threads in a pool call wait_block on futures running on the same pool or a pool depending on it.
A good rule to avoid deadlocks is to run this from outside of any pool, or to have an acyclic order between pools where wait_block is only called from a pool on futures evaluated in a pool that comes lower in the hierarchy. If this rule is broken, it is possible for all threads in a pool to wait for futures that can only make progress on these same threads, hence the deadlock.
val wait_block_exn : 'a t -> 'aSame as wait_block but re-raises the exception if the future failed.
Infix operators
These combinators run on either the current pool (if present), or on the same thread that just fulfilled the previous future if not.
They were previously present as module Infix_local and val infix, but are now simplified.
module Infix : sig ... endmodule Infix_local = Infix
diff --git a/moonpool/Moonpool/Immediate_runner/index.html b/moonpool/Moonpool/Immediate_runner/index.html
index d690cf9b..fb0ec3a5 100644
--- a/moonpool/Moonpool/Immediate_runner/index.html
+++ b/moonpool/Moonpool/Immediate_runner/index.html
@@ -1,2 +1,2 @@
-Immediate_runner (moonpool.Moonpool.Immediate_runner) Module Moonpool.Immediate_runner
Runner that runs tasks in the caller thread.
This is removed since NEXT_RELEASE, and replaced by Moonpool_fib.Main.
+Immediate_runner (moonpool.Moonpool.Immediate_runner) Module Moonpool.Immediate_runner
Runner that runs tasks in the caller thread.
This is removed since 0.6, and replaced by Moonpool_fib.Main.
diff --git a/moonpool/Moonpool/Runner/index.html b/moonpool/Moonpool/Runner/index.html
index 44a06c03..8dd17a6d 100644
--- a/moonpool/Moonpool/Runner/index.html
+++ b/moonpool/Moonpool/Runner/index.html
@@ -1,2 +1,2 @@
-Runner (moonpool.Moonpool.Runner) Module Moonpool.Runner
Interface for runners.
This provides an abstraction for running tasks in the background, which is implemented by various thread pools.
A runner.
If a runner is no longer needed, shutdown can be used to signal all worker threads in it to stop (after they finish their work), and wait for them to stop.
The threads are distributed across a fixed domain pool (whose size is determined by Domain.recommended_domain_count on OCaml 5, and simple the single runtime on OCaml 4).
val size : t -> intNumber of threads/workers.
val num_tasks : t -> intCurrent number of tasks. This is at best a snapshot, useful for metrics and debugging.
val shutdown : t -> unitShutdown the runner and wait for it to terminate. Idempotent.
val shutdown_without_waiting : t -> unitShutdown the pool, and do not wait for it to terminate. Idempotent.
val run_async : ?ls:Task_local_storage.t -> t -> task -> unitrun_async pool f schedules f for later execution on the runner in one of the threads. f() will run on one of the runner's worker threads/domains.
val run_wait_block : ?ls:Task_local_storage.t -> t -> (unit -> 'a) -> 'arun_wait_block pool f schedules f for later execution on the pool, like run_async. It then blocks the current thread until f() is done executing, and returns its result. If f() raises an exception, then run_wait_block pool f will raise it as well.
NOTE be careful with deadlocks (see notes in Fut.wait_block about the required discipline to avoid deadlocks).
val dummy : tRunner that fails when scheduling tasks on it. Calling run_async on it will raise Failure.
Implementing runners
module For_runner_implementors : sig ... endThis module is specifically intended for users who implement their own runners. Regular users of Moonpool should not need to look at it.
val get_current_runner : unit -> t optionAccess the current runner. This returns Some r if the call happens on a thread that belongs in a runner.
val get_current_storage : unit -> Task_local_storage.t optionget_current_storage runner gets the local storage for the currently running task.
+Runner (moonpool.Moonpool.Runner) Module Moonpool.Runner
Interface for runners.
This provides an abstraction for running tasks in the background, which is implemented by various thread pools.
A runner.
If a runner is no longer needed, shutdown can be used to signal all worker threads in it to stop (after they finish their work), and wait for them to stop.
The threads are distributed across a fixed domain pool (whose size is determined by Domain.recommended_domain_count on OCaml 5, and simple the single runtime on OCaml 4).
val size : t -> intNumber of threads/workers.
val num_tasks : t -> intCurrent number of tasks. This is at best a snapshot, useful for metrics and debugging.
val shutdown : t -> unitShutdown the runner and wait for it to terminate. Idempotent.
val shutdown_without_waiting : t -> unitShutdown the pool, and do not wait for it to terminate. Idempotent.
val run_async : ?ls:Task_local_storage.t -> t -> task -> unitrun_async pool f schedules f for later execution on the runner in one of the threads. f() will run on one of the runner's worker threads/domains.
val run_wait_block : ?ls:Task_local_storage.t -> t -> (unit -> 'a) -> 'arun_wait_block pool f schedules f for later execution on the pool, like run_async. It then blocks the current thread until f() is done executing, and returns its result. If f() raises an exception, then run_wait_block pool f will raise it as well.
NOTE be careful with deadlocks (see notes in Fut.wait_block about the required discipline to avoid deadlocks).
val dummy : tRunner that fails when scheduling tasks on it. Calling run_async on it will raise Failure.
Implementing runners
module For_runner_implementors : sig ... endThis module is specifically intended for users who implement their own runners. Regular users of Moonpool should not need to look at it.
val get_current_runner : unit -> t optionAccess the current runner. This returns Some r if the call happens on a thread that belongs in a runner.
val get_current_storage : unit -> Task_local_storage.t optionget_current_storage runner gets the local storage for the currently running task.
diff --git a/moonpool/Moonpool/Task_local_storage/index.html b/moonpool/Moonpool/Task_local_storage/index.html
index 426c74c4..984ab8ea 100644
--- a/moonpool/Moonpool/Task_local_storage/index.html
+++ b/moonpool/Moonpool/Task_local_storage/index.html
@@ -1,5 +1,5 @@
-Task_local_storage (moonpool.Moonpool.Task_local_storage) Module Moonpool.Task_local_storage
Task-local storage.
This storage is associated to the current task, just like thread-local storage is associated with the current thread. The storage is carried along in case the current task is suspended.
Underlying storage for a task. This is mutable and not thread-safe.
val dummy : tval new_key : init:(unit -> 'a) -> unit -> 'a keynew_key ~init () makes a new key. Keys are expensive and should never be allocated dynamically or in a loop. The correct pattern is, at toplevel:
let k_foo : foo Task_ocal_storage.key =
+Task_local_storage (moonpool.Moonpool.Task_local_storage) Module Moonpool.Task_local_storage
Task-local storage.
This storage is associated to the current task, just like thread-local storage is associated with the current thread. The storage is carried along in case the current task is suspended.
Underlying storage for a task. This is mutable and not thread-safe.
val dummy : tval new_key : init:(unit -> 'a) -> unit -> 'a keynew_key ~init () makes a new key. Keys are expensive and should never be allocated dynamically or in a loop. The correct pattern is, at toplevel:
let k_foo : foo Task_ocal_storage.key =
Task_local_storage.new_key ~init:(fun () -> make_foo ()) ()
(* … *)
diff --git a/moonpool/Moonpool/Ws_pool/index.html b/moonpool/Moonpool/Ws_pool/index.html
index 5afb3e60..261af041 100644
--- a/moonpool/Moonpool/Ws_pool/index.html
+++ b/moonpool/Moonpool/Ws_pool/index.html
@@ -1,9 +1,9 @@
-Ws_pool (moonpool.Moonpool.Ws_pool) Module Moonpool.Ws_pool
Work-stealing thread pool.
A pool of threads with a worker-stealing scheduler. The pool contains a fixed number of threads that wait for work items to come, process these, and loop.
This is good for CPU-intensive tasks that feature a lot of small tasks. Note that tasks will not always be processed in the order they are scheduled, so this is not great for workloads where the latency of individual tasks matter (for that see Fifo_pool).
This implements Runner.t since 0.3.
If a pool is no longer needed, shutdown can be used to signal all threads in it to stop (after they finish their work), and wait for them to stop.
The threads are distributed across a fixed domain pool (whose size is determined by Domain.recommended_domain_count on OCaml 5, and simply the single runtime on OCaml 4).
include module type of Runner
A runner.
If a runner is no longer needed, shutdown can be used to signal all worker threads in it to stop (after they finish their work), and wait for them to stop.
The threads are distributed across a fixed domain pool (whose size is determined by Domain.recommended_domain_count on OCaml 5, and simple the single runtime on OCaml 4).
val size : t -> intNumber of threads/workers.
val num_tasks : t -> intCurrent number of tasks. This is at best a snapshot, useful for metrics and debugging.
val shutdown : t -> unitShutdown the runner and wait for it to terminate. Idempotent.
val shutdown_without_waiting : t -> unitShutdown the pool, and do not wait for it to terminate. Idempotent.
val run_async : ?ls:Task_local_storage.t -> t -> task -> unitrun_async pool f schedules f for later execution on the runner in one of the threads. f() will run on one of the runner's worker threads/domains.
val run_wait_block : ?ls:Task_local_storage.t -> t -> (unit -> 'a) -> 'arun_wait_block pool f schedules f for later execution on the pool, like run_async. It then blocks the current thread until f() is done executing, and returns its result. If f() raises an exception, then run_wait_block pool f will raise it as well.
NOTE be careful with deadlocks (see notes in Fut.wait_block about the required discipline to avoid deadlocks).
val dummy : tRunner that fails when scheduling tasks on it. Calling run_async on it will raise Failure.
Implementing runners
module For_runner_implementors : sig ... endThis module is specifically intended for users who implement their own runners. Regular users of Moonpool should not need to look at it.
val get_current_runner : unit -> t optionAccess the current runner. This returns Some r if the call happens on a thread that belongs in a runner.
val get_current_storage : unit -> Task_local_storage.t optionget_current_storage runner gets the local storage for the currently running task.
type ('a, 'b) create_args =
+Ws_pool (moonpool.Moonpool.Ws_pool) Module Moonpool.Ws_pool
Work-stealing thread pool.
A pool of threads with a worker-stealing scheduler. The pool contains a fixed number of threads that wait for work items to come, process these, and loop.
This is good for CPU-intensive tasks that feature a lot of small tasks. Note that tasks will not always be processed in the order they are scheduled, so this is not great for workloads where the latency of individual tasks matter (for that see Fifo_pool).
This implements Runner.t since 0.3.
If a pool is no longer needed, shutdown can be used to signal all threads in it to stop (after they finish their work), and wait for them to stop.
The threads are distributed across a fixed domain pool (whose size is determined by Domain.recommended_domain_count on OCaml 5, and simply the single runtime on OCaml 4).
include module type of Runner
A runner.
If a runner is no longer needed, shutdown can be used to signal all worker threads in it to stop (after they finish their work), and wait for them to stop.
The threads are distributed across a fixed domain pool (whose size is determined by Domain.recommended_domain_count on OCaml 5, and simple the single runtime on OCaml 4).
val size : t -> intNumber of threads/workers.
val num_tasks : t -> intCurrent number of tasks. This is at best a snapshot, useful for metrics and debugging.
val shutdown : t -> unitShutdown the runner and wait for it to terminate. Idempotent.
val shutdown_without_waiting : t -> unitShutdown the pool, and do not wait for it to terminate. Idempotent.
val run_async : ?ls:Task_local_storage.t -> t -> task -> unitrun_async pool f schedules f for later execution on the runner in one of the threads. f() will run on one of the runner's worker threads/domains.
val run_wait_block : ?ls:Task_local_storage.t -> t -> (unit -> 'a) -> 'arun_wait_block pool f schedules f for later execution on the pool, like run_async. It then blocks the current thread until f() is done executing, and returns its result. If f() raises an exception, then run_wait_block pool f will raise it as well.
NOTE be careful with deadlocks (see notes in Fut.wait_block about the required discipline to avoid deadlocks).
val dummy : tRunner that fails when scheduling tasks on it. Calling run_async on it will raise Failure.
Implementing runners
module For_runner_implementors : sig ... endThis module is specifically intended for users who implement their own runners. Regular users of Moonpool should not need to look at it.
val get_current_runner : unit -> t optionAccess the current runner. This returns Some r if the call happens on a thread that belongs in a runner.
val get_current_storage : unit -> Task_local_storage.t optionget_current_storage runner gets the local storage for the currently running task.
type ('a, 'b) create_args =
?on_init_thread:(dom_id:int -> t_id:int -> unit -> unit) ->
?on_exit_thread:(dom_id:int -> t_id:int -> unit -> unit) ->
?on_exn:(exn -> Stdlib.Printexc.raw_backtrace -> unit) ->
?around_task:((t -> 'b) * (t -> 'b -> unit)) ->
?num_threads:int ->
?name:string ->
- 'aval create : (unit -> t, _) create_argscreate () makes a new thread pool.
val with_ : (unit -> (t -> 'a) -> 'a, _) create_args
+ 'aval create : (unit -> t, _) create_argscreate () makes a new thread pool.
val with_ : (unit -> (t -> 'a) -> 'a, _) create_args
diff --git a/moonpool/Moonpool/index.html b/moonpool/Moonpool/index.html
index ab4b9899..58aa74ac 100644
--- a/moonpool/Moonpool/index.html
+++ b/moonpool/Moonpool/index.html
@@ -1,2 +1,2 @@
-Moonpool (moonpool.Moonpool) Module Moonpool
Moonpool
A pool within a bigger pool (ie the ocean). Here, we're talking about pools of Thread.t that are dispatched over several Domain.t to enable parallelism.
We provide several implementations of pools with distinct scheduling strategies, alongside some concurrency primitives such as guarding locks (Lock.t) and futures (Fut.t).
module Ws_pool : sig ... endWork-stealing thread pool.
module Fifo_pool : sig ... endA simple thread pool in FIFO order.
module Background_thread : sig ... endA simple runner with a single background thread.
module Runner : sig ... endInterface for runners.
module Immediate_runner : sig ... endRunner that runs tasks in the caller thread.
module Exn_bt : sig ... endException with backtrace.
val start_thread_on_some_domain : ('a -> unit) -> 'a -> Thread.tSimilar to Thread.create, but it picks a background domain at random to run the thread. This ensures that we don't always pick the same domain to run all the various threads needed in an application (timers, event loops, etc.)
val run_async : ?ls:Task_local_storage.t -> Runner.t -> (unit -> unit) -> unitrun_async runner task schedules the task to run on the given runner. This means task() will be executed at some point in the future, possibly in another thread.
val run_wait_block : ?ls:Task_local_storage.t -> Runner.t -> (unit -> 'a) -> 'arun_wait_block runner f schedules f for later execution on the runner, like run_async. It then blocks the current thread until f() is done executing, and returns its result. If f() raises an exception, then run_wait_block pool f will raise it as well.
NOTE be careful with deadlocks (see notes in Fut.wait_block about the required discipline to avoid deadlocks).
Number of threads recommended to saturate the CPU. For IO pools this makes little sense (you might want more threads than this because many of them will be blocked most of the time).
spawn ~on f runs f() on the runner (a thread pool typically) and returns a future result for it. See Fut.spawn.
val spawn_on_current_runner : (unit -> 'a) -> 'a Fut.tmodule Lock : sig ... endMutex-protected resource.
module Fut : sig ... endFutures.
module Chan : sig ... endChannels.
module Task_local_storage : sig ... endTask-local storage.
module Thread_local_storage = Moonpool_private.Thread_local_storage_module Blocking_queue : sig ... endA simple blocking queue.
module Bounded_queue : sig ... endA blocking queue of finite size.
module Atomic = Moonpool_private.Atomic_Atomic values.
+Moonpool (moonpool.Moonpool) Module Moonpool
Moonpool
A pool within a bigger pool (ie the ocean). Here, we're talking about pools of Thread.t that are dispatched over several Domain.t to enable parallelism.
We provide several implementations of pools with distinct scheduling strategies, alongside some concurrency primitives such as guarding locks (Lock.t) and futures (Fut.t).
module Ws_pool : sig ... endWork-stealing thread pool.
module Fifo_pool : sig ... endA simple thread pool in FIFO order.
module Background_thread : sig ... endA simple runner with a single background thread.
module Runner : sig ... endInterface for runners.
module Immediate_runner : sig ... endRunner that runs tasks in the caller thread.
module Exn_bt : sig ... endException with backtrace.
val start_thread_on_some_domain : ('a -> unit) -> 'a -> Thread.tSimilar to Thread.create, but it picks a background domain at random to run the thread. This ensures that we don't always pick the same domain to run all the various threads needed in an application (timers, event loops, etc.)
val run_async : ?ls:Task_local_storage.t -> Runner.t -> (unit -> unit) -> unitrun_async runner task schedules the task to run on the given runner. This means task() will be executed at some point in the future, possibly in another thread.
val run_wait_block : ?ls:Task_local_storage.t -> Runner.t -> (unit -> 'a) -> 'arun_wait_block runner f schedules f for later execution on the runner, like run_async. It then blocks the current thread until f() is done executing, and returns its result. If f() raises an exception, then run_wait_block pool f will raise it as well.
NOTE be careful with deadlocks (see notes in Fut.wait_block about the required discipline to avoid deadlocks).
Number of threads recommended to saturate the CPU. For IO pools this makes little sense (you might want more threads than this because many of them will be blocked most of the time).
spawn ~on f runs f() on the runner (a thread pool typically) and returns a future result for it. See Fut.spawn.
val spawn_on_current_runner : (unit -> 'a) -> 'a Fut.tmodule Lock : sig ... endMutex-protected resource.
module Fut : sig ... endFutures.
module Chan : sig ... endChannels.
module Task_local_storage : sig ... endTask-local storage.
module Thread_local_storage = Moonpool_private.Thread_local_storage_module Blocking_queue : sig ... endA simple blocking queue.
module Bounded_queue : sig ... endA blocking queue of finite size.
module Atomic = Moonpool_private.Atomic_Atomic values.
diff --git a/moonpool/Moonpool_dpool/index.html b/moonpool/Moonpool_dpool/index.html
index a26ad039..0237fd66 100644
--- a/moonpool/Moonpool_dpool/index.html
+++ b/moonpool/Moonpool_dpool/index.html
@@ -1,2 +1,2 @@
-Moonpool_dpool (moonpool.Moonpool_dpool) Module Moonpool_dpool
Static pool of domains.
These domains are shared between all the pools in moonpool. The rationale is that we should not have more domains than cores, so it's easier to reserve exactly that many domain slots, and run more flexible thread pools on top (each domain being shared by potentially multiple threads from multiple pools).
The pool should not contain actual domains if it's not in use, ie if no runner is presently actively using one or more of the domain slots.
NOTE: Interface is still experimental.
type domain = Moonpool_private.Domain_.tLow level interface for resouce handling
Be very cautious with this interface, or resource leaks might occur.
run_on i f runs f() on the domain with index i. Precondition: 0 <= i < n_domains(). The thread must call decr_on with i once it's done.
+Moonpool_dpool (moonpool.Moonpool_dpool) Module Moonpool_dpool
Static pool of domains.
These domains are shared between all the pools in moonpool. The rationale is that we should not have more domains than cores, so it's easier to reserve exactly that many domain slots, and run more flexible thread pools on top (each domain being shared by potentially multiple threads from multiple pools).
The pool should not contain actual domains if it's not in use, ie if no runner is presently actively using one or more of the domain slots.
NOTE: Interface is still experimental.
type domain = Moonpool_private.Domain_.tLow level interface for resouce handling
Be very cautious with this interface, or resource leaks might occur.
run_on i f runs f() on the domain with index i. Precondition: 0 <= i < n_domains(). The thread must call decr_on with i once it's done.
diff --git a/moonpool/Moonpool_fib/Main/index.html b/moonpool/Moonpool_fib/Main/index.html
index f59ef805..dd3f049b 100644
--- a/moonpool/Moonpool_fib/Main/index.html
+++ b/moonpool/Moonpool_fib/Main/index.html
@@ -1,2 +1,2 @@
-Main (moonpool.Moonpool_fib.Main) Module Moonpool_fib.Main
Main thread.
This is evolved from Moonpool.Immediate_runner, but unlike it, this API assumes you run it in a thread (possibly the main thread) which will block until the initial computation is done.
This means it's reasonable to use Main.main (fun () -> do_everything) at the beginning of the program. Other Moonpool pools can be created for background tasks, etc. to do the heavy lifting, and the main thread (inside this immediate runner) can coordinate tasks via Fiber.await.
Aside from the fact that this blocks the caller thread, it is fairly similar to Background_thread in that there's a single worker to process tasks/fibers.
This handles effects, including the ones in Fiber.
val main : (Moonpool.Runner.t -> 'a) -> 'amain f runs f() in a scope that handles effects, including Fiber.await.
This scope can run background tasks as well, in a cooperative fashion.
+Main (moonpool.Moonpool_fib.Main) Module Moonpool_fib.Main
Main thread.
This is evolved from Moonpool.Immediate_runner, but unlike it, this API assumes you run it in a thread (possibly the main thread) which will block until the initial computation is done.
This means it's reasonable to use Main.main (fun () -> do_everything) at the beginning of the program. Other Moonpool pools can be created for background tasks, etc. to do the heavy lifting, and the main thread (inside this immediate runner) can coordinate tasks via Fiber.await.
Aside from the fact that this blocks the caller thread, it is fairly similar to Background_thread in that there's a single worker to process tasks/fibers.
This handles effects, including the ones in Fiber.
val main : (Moonpool.Runner.t -> 'a) -> 'amain f runs f() in a scope that handles effects, including Fiber.await.
This scope can run background tasks as well, in a cooperative fashion.
diff --git a/moonpool/Moonpool_fib/index.html b/moonpool/Moonpool_fib/index.html
index 90bc0690..11cee127 100644
--- a/moonpool/Moonpool_fib/index.html
+++ b/moonpool/Moonpool_fib/index.html
@@ -1,2 +1,2 @@
-Moonpool_fib (moonpool.Moonpool_fib) Module Moonpool_fib
Fibers for moonpool.
See Fiber for the most important explanations.
module Fiber : sig ... endFibers.
module Fls : sig ... endFiber-local storage.
module Handle : sig ... endThe unique name of a fiber.
module Main : sig ... endMain thread.
include module type of struct include Fiber end
type cancel_callback = Moonpool.Exn_bt.t -> unitA callback used in case of cancellation
type 'a t = 'a Fiber.{Private_}1.tA fiber returning a value of type 'a.
val res : 'a t -> 'a Moonpool.Fut.tFuture result of the fiber.
type 'a callback = 'a Moonpool.Exn_bt.result -> unitCallbacks that are called when a fiber is done.
Type erased fiber
val return : 'a -> 'a tval fail : Moonpool.Exn_bt.t -> _ tval self : unit -> anyself () is the current fiber. Must be run from inside a fiber.
val peek : 'a t -> 'a Moonpool.Fut.or_error optionPeek inside the future result
val is_done : _ t -> boolHas the fiber completed?
val is_cancelled : _ t -> boolHas the fiber completed with a failure?
val is_success : _ t -> boolHas the fiber completed with a value?
val await : 'a t -> 'aawait fib is like Fut.await (res fib)
val wait_block_exn : 'a t -> 'await_block_exn fib is Fut.wait_block_exn (res fib). NOTE: See Fut.wait_block for warnings about deadlocks.
val wait_block : 'a t -> 'a Moonpool.Fut.or_errorwait_block fib is Fut.wait_block (res fib). NOTE: See Fut.wait_block for warnings about deadlocks.
Check if the current fiber is cancelled, in which case this raises. Must be run from inside a fiber.
type cancel_handle = Fiber.cancel_handleAn opaque handle for a single cancel callback in a fiber
val add_on_cancel : _ t -> cancel_callback -> cancel_handleadd_on_cancel fib cb adds cb to the list of cancel callbacks for fib. If fib is already cancelled, cb is called immediately.
val remove_on_cancel : _ t -> cancel_handle -> unitremove_on_cancel fib h removes the cancel callback associated with handle h.
val with_on_cancel : _ t -> cancel_callback -> (unit -> 'a) -> 'awith_on_cancel fib cb (fun () -> <e>) evaluates e in a scope in which, if the fiber fib is cancelled, cb() is called. If e returns without the fiber being cancelled, this callback is removed.
val with_on_self_cancel : cancel_callback -> (unit -> 'a) -> 'awith_on_self_cancel cb f calls f() in a scope where cb is added to the cancel callbacks of the current fiber; and f() terminates, cb is removed from the list.
Wait for fiber to be done and call the callback with the result. If the fiber is done already then the callback is invoked immediately with its result.
val spawn_top : on:Moonpool.Runner.t -> (unit -> 'a) -> 'a tspawn_top ~on f spawns a new (toplevel) fiber onto the given runner. This fiber is not the child of any other fiber: its lifetime is only determined by the lifetime of f().
val spawn : ?on:Moonpool.Runner.t -> ?protect:bool -> (unit -> 'a) -> 'a tspawn ~protect f spawns a sub-fiber f_child from a running fiber parent. The sub-fiber f_child is attached to the current fiber and fails if the current fiber parent fails.
include module type of struct include Main end
val main : (Moonpool.Runner.t -> 'a) -> 'amain f runs f() in a scope that handles effects, including Fiber.await.
This scope can run background tasks as well, in a cooperative fashion.
+Moonpool_fib (moonpool.Moonpool_fib) Module Moonpool_fib
Fibers for moonpool.
See Fiber for the most important explanations.
module Fiber : sig ... endFibers.
module Fls : sig ... endFiber-local storage.
module Handle : sig ... endThe unique name of a fiber.
module Main : sig ... endMain thread.
include module type of struct include Fiber end
type cancel_callback = Moonpool.Exn_bt.t -> unitA callback used in case of cancellation
type 'a t = 'a Fiber.{Private_}1.tA fiber returning a value of type 'a.
val res : 'a t -> 'a Moonpool.Fut.tFuture result of the fiber.
type 'a callback = 'a Moonpool.Exn_bt.result -> unitCallbacks that are called when a fiber is done.
Type erased fiber
val return : 'a -> 'a tval fail : Moonpool.Exn_bt.t -> _ tval self : unit -> anyself () is the current fiber. Must be run from inside a fiber.
val peek : 'a t -> 'a Moonpool.Fut.or_error optionPeek inside the future result
val is_done : _ t -> boolHas the fiber completed?
val is_cancelled : _ t -> boolHas the fiber completed with a failure?
val is_success : _ t -> boolHas the fiber completed with a value?
val await : 'a t -> 'aawait fib is like Fut.await (res fib)
val wait_block_exn : 'a t -> 'await_block_exn fib is Fut.wait_block_exn (res fib). NOTE: See Fut.wait_block for warnings about deadlocks.
val wait_block : 'a t -> 'a Moonpool.Fut.or_errorwait_block fib is Fut.wait_block (res fib). NOTE: See Fut.wait_block for warnings about deadlocks.
Check if the current fiber is cancelled, in which case this raises. Must be run from inside a fiber.
type cancel_handle = Fiber.cancel_handleAn opaque handle for a single cancel callback in a fiber
val add_on_cancel : _ t -> cancel_callback -> cancel_handleadd_on_cancel fib cb adds cb to the list of cancel callbacks for fib. If fib is already cancelled, cb is called immediately.
val remove_on_cancel : _ t -> cancel_handle -> unitremove_on_cancel fib h removes the cancel callback associated with handle h.
val with_on_cancel : _ t -> cancel_callback -> (unit -> 'a) -> 'awith_on_cancel fib cb (fun () -> <e>) evaluates e in a scope in which, if the fiber fib is cancelled, cb() is called. If e returns without the fiber being cancelled, this callback is removed.
val with_on_self_cancel : cancel_callback -> (unit -> 'a) -> 'awith_on_self_cancel cb f calls f() in a scope where cb is added to the cancel callbacks of the current fiber; and f() terminates, cb is removed from the list.
Wait for fiber to be done and call the callback with the result. If the fiber is done already then the callback is invoked immediately with its result.
val spawn_top : on:Moonpool.Runner.t -> (unit -> 'a) -> 'a tspawn_top ~on f spawns a new (toplevel) fiber onto the given runner. This fiber is not the child of any other fiber: its lifetime is only determined by the lifetime of f().
val spawn : ?on:Moonpool.Runner.t -> ?protect:bool -> (unit -> 'a) -> 'a tspawn ~protect f spawns a sub-fiber f_child from a running fiber parent. The sub-fiber f_child is attached to the current fiber and fails if the current fiber parent fails.
include module type of struct include Main end
val main : (Moonpool.Runner.t -> 'a) -> 'amain f runs f() in a scope that handles effects, including Fiber.await.
This scope can run background tasks as well, in a cooperative fashion.
diff --git a/moonpool/_doc-dir/CHANGES.md b/moonpool/_doc-dir/CHANGES.md
index 3e855a20..a295fa77 100644
--- a/moonpool/_doc-dir/CHANGES.md
+++ b/moonpool/_doc-dir/CHANGES.md
@@ -1,4 +1,29 @@
+# 0.6
+
+- breaking: remove `Immediate_runner` (bug prone and didn't
+ handle effects). `Moonpool_fib.main` can be used to handle
+ effects in the main function.
+- remove deprecated alias `Moonpool.Pool`
+
+- feat: add structured concurrency sub-library `moonpool.fib` with
+ fibers. Fibers can use `await` and spawn other fibers that will
+ be appropriately cancelled when their parent is.
+- feat: add add `moonpool-lwt` as an experimental bridge between moonpool and lwt.
+ This allows moonpool runners to be used from within Lwt to
+ perform background computations, and conversely to call Lwt from
+ moonpool with some precautions.
+- feat: task-local storage in the main moonpool runners, available from
+ fibers and regular tasks.
+- feat: add `Exn_bt` to core
+- feat: add `Runner.dummy`
+- make `moonpool.forkjoin` optional (only on OCaml >= 5.0)
+- feat: add `Fut.Advanced.barrier_on_abstract_container_of_futures`
+- feat: add `Fut.map_list`
+
+- refactor: split off domain pool to `moonpool.dpool`
+- fix too early exit in Ws_pool
+
# 0.5.1
- fix `Ws_pool`: workers would exit before processing