Await_kernel.Awaitt is the type of implementations of awaiting. Operations that need to await something take a t that provides an implementation of awaiting for them to use.
Any awaiting operation can be terminated by the awaiting implementation, which results in a Terminated exception being raised.
val with_ :
'c 'r. terminator:Terminator.t @ local ->
(yield:('c @ local -> Base.unit) Base.or_null @ local ->
(await:('c @ local -> (Trigger.t -> Base.unit) @ local) @ local ->
('c @ local ->
(f:(t @ local -> 'r @ local unique once) @ local once ->
'r @ local unique once) @ local) @ local) @ local) @ local @@ portablewith_ terminator ~yield ~await c ~f calls f with an awaiter that has terminator as its terminator, yield c as its implementation of yield, and await c as its implementation of await.
val create_global :
terminator:Terminator.t ->
yield:('c @ portable contended -> Base.unit) Base.or_null @ portable ->
await:
('c @ portable contended -> (Trigger.t -> Base.unit) @ portable) @ portable ->
'c @ portable contended ->
t @@ portablecreate_global ~terminator ~yield ~await c creates a global awaiter with yield c as its implementation of yield and await c as its implementation of await. Both yield and await must be portable as the returned Await.t is not local, allowing it to escape to other capsules.
val terminator : t @ local -> Terminator.t @ local @@ portableterminator t is the terminator associated with t. Awaiting operations should attempt to cancel themselves if they have been terminated, raising Terminated if they succeed in doing so.
val await :
t @ local ->
(on_terminate:Trigger.Source.t ->
(await_on:Trigger.t ->
Base.unit) @ local) @ local @@ portableawait t ~on_terminate ~await_on will use t to attach on_terminate to be signalled on termination and to wait until await_on has been signaled.
Note that the on_terminate trigger may not be used by await. The await_on trigger will be used before await returns.
await_until_terminated t trigger is equivalent to await t ~on_terminate:(Trigger.source trigger) ~await_on:trigger.
val await_until_terminated_or_canceled :
t @ local ->
(Cancellation.t @ local ->
(Trigger.t ->
Base.unit) @ local) @ local @@ portableawait_until_terminated_or_canceled t c trigger is like await_until_terminated t trigger except it will also return in case the cancellation token has been cancelled .
val await_with_terminate :
t @ local ->
(Trigger.t ->
(terminate:('r @ unique once portable contended -> Base.unit) @ once portable ->
('r @ unique once portable contended ->
Base.unit) @ local once) @ local) @ local @@ portableawait_with_terminate t trigger ~terminate r will attach a trigger to call terminate r to the terminator of t and wait until trigger has been signalled.
val await_with_terminate_or_cancel :
t @ local ->
(Cancellation.t @ local ->
(Trigger.t ->
(terminate_or_cancel:
('r @ unique once portable contended -> Base.unit) @ once portable ->
('r @ unique once portable contended ->
Base.unit) @ local once) @ local) @ local) @ local @@ portableawait_with_terminate_or_cancel t c trigger ~terminate_or_cancel r will attach a trigger to call terminate_or_cancel r to both the terminator of t and to the given cancellation token c and then wait until trigger has been signalled.
is_terminated t is Terminator.is_terminated (terminator t).
val with_terminator :
t @ local ->
(Terminator.t @ local ->
t @ local) @ local @@ portablewith_terminator t new_terminator is an awaiter u like t where terminator u is new_terminator.
The main use case of with_terminator is to protect a blocking operation from being terminated by replacing the terminator with Terminator.never:
blocking_operation (with_terminator t Terminator.never)await_never_terminated t trigger is await_until_terminated (with_terminator t Terminator.never) trigger.
yield t yields to the scheduler using the implementation of yielding associated with t.
module For_testing : sig ... end