package octez-libs
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=c6df840ebbf115e454db949028c595bec558a59a66cade73b52a6d099d6fa4d4
sha512=d8aee903b9fe130d73176bc8ec38b78c9ff65317da3cb4f3415f09af0c625b4384e7498201fdb61aa39086a7d5d409d0ab3423f9bc3ab989a680cf444a79bc13
doc/octez-libs.stdlib/Tezos_stdlib/Lwt_utils/index.html
Module Tezos_stdlib.Lwt_utils
Source
val worker :
string ->
on_event:(string -> [ `Ended | `Failed of string | `Started ] -> unit Lwt.t) ->
run:(unit -> unit Lwt.t) ->
cancel:(unit -> unit Lwt.t) ->
unit Lwt.t
worker name ~on_event ~run ~cancel
internally calls run ()
(which returns a promise p
) and returns its own promise work
. If p
becomes fulfilled, then work
also becomes fulfilled. If p
becomes rejected then cancel ()
is called and, once its promise is resolved, work
is fulfilled. This gives the opportunity for the function cancel
to clean-up some resources.
The function on_event
is called at different times (start, failure, end) and is mostly meant as a logging mechanism but can also be used for other purposes such as synchronization between different workers.
If the promises returned by on_event
or cancel
raise an exception or become rejected, the exception/failure is simply ignored and the promise is treated as having resolved anyway.
Note that the promise work
returned by the worker
function is not cancelable. If you need to cancel the promise returned by run
, you need to embed your own synchronization system within run
. E.g.,
let p, r = Lwt.wait in let run () = let main = … in Lwt.pick [main ; p] in