Async.Call_handlerCall handlers.
A call handler wraps an asynchronous function call f before it starts executing. It is responsible for making the f () call. The handler is also used to make all the asynchronous calls done by f itself and its descendents.
The composition order of handlers matches the syntactic scope: outer scopes are called after inner ones. More precisely in the example below f is called with (Call_handler.compose h0 h1).handle f:
let h0 = Fun.Async.Call_Handler.{ handle = … }
let h1 = Fun.Async.Call_Handler.{ handle = … }
let ret =
Fun.Async.call ~handler:h0 @@ fun () ->
Fun.Async.call ~handler:h1 @@
f (* Formally: h0.handle (fun () -> h1.handle f) *)Handlers can be used to make sure effects are handled in asynchronous function calls according to expected syntactic scopes, see the cookbook.
The type for handlers.
Given a function f, handle must call f () and returns its value or exception.
Warning. handle must be synchronization safe. It can be executed in parallel and/or on multiple different domains over time.
val call : t -> (unit -> 'a) -> 'acall h f is h.handle f.
val none : tnone is a handler that just executes the function.