package lsp
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=e4e56590b9af02160e5af7733763897d7cfe3f9b876692af4d4184ab0fce4bcb
sha512=724d5190a678ca8a3f3c13915cbfcf8d3cce8efa43e0dde130b14c45065b6ccd22507951e79977bcecf361c7928f271d312b87642bb2c52f33669c3e952a7e1b
doc/lsp.fiber/Fiber/index.html
Module Fiber
Concurrency library
This module implements "structured concurrency".
Generals
Type of fiber. A fiber represent a suspended computation. Note that using the same fiber twice will execute it twice, which is probably not what you want. To share the result of a fiber, use an Ivar.t
.
val return : 'a -> 'a t
Create a fiber that has already terminated.
Converts a thunk to a fiber, making sure the thunk runs in the context of the fiber (rather than applied in the current context).
Equivalent to (>>=) (return ())
, but more explicit.
val never : 'a t
Fiber that never completes.
module O : sig ... end
Joining
The following combinators are helpers to combine the result of several fibers into one. Note that they do not introduce parallelism.
Forking + joining
The following functions combine forking 2 or more fibers followed by joining the results. The execution of the various fibers might be interleaved, however once the combining fiber has terminated, it is guaranteed that there are no fibers lingering around.
Start two fibers and wait for their results.
Same but assume the first fiber returns unit
.
Local storage
module Var : sig ... end
Variables local to a fiber
Error handling
val with_error_handler :
(unit -> 'a t) ->
on_error:(Stdune.Exn_with_backtrace.t -> unit) ->
'a t
with_error_handler f ~on_error
calls on_error
for every exception raised during the execution of f
. This include exceptions raised when calling f ()
or during the execution of fibers after f ()
has returned. Exceptions raised by on_error
are passed on to the parent error handler.
It is guaranteed that after the fiber has returned a value, on_error
will never be called.
val fold_errors :
(unit -> 'a t) ->
init:'b ->
on_error:(Stdune.Exn_with_backtrace.t -> 'b -> 'b) ->
('a, 'b) Stdune.Result.t t
fold_errors f ~init ~on_error
calls on_error
for every exception raised during the execution of f
. This include exceptions raised when calling f ()
or during the execution of fibers after f ()
has returned.
Exceptions raised by on_error
are passed on to the parent error handler.
val collect_errors :
(unit -> 'a t) ->
('a, Stdune.Exn_with_backtrace.t list) Stdune.Result.t t
collect_errors f
is: fold_errors f ~init:[] ~on_error:(fun e l -> e :: l)
finalize f ~finally
runs finally
after f ()
has terminated, whether it fails or succeeds.
Synchronization
module Ivar : sig ... end
Write once variables
module Mvar : sig ... end
Mailbox variables
module Mutex : sig ... end
module Throttle : sig ... end
Limit the number of jobs
module Sequence : sig ... end
Running fibers
run t ~iter
runs a fiber until it terminates. iter
is used to implement the scheduler, it should block waiting for an event and return an ivar to fill.
val fork_and_race :
(unit -> 'a t) ->
(unit -> 'b t) ->
('a, 'b) Stdune.Either.t t