Asynchronous utility functions. More...
Macros | |
#define | using_cancel_scope() |
Execute under a cancelation scope. More... | |
Typedefs | |
typedef void() | nodec_actionfun_t() |
Type of actions with no arguments and no return value. | |
Functions | |
void | async_scoped_cancel () |
Asynchronously cancel all outstanding requests under the same cancelation scope. More... | |
bool | async_scoped_is_canceled () |
Is the current scope canceled? | |
void | async_interleave (size_t n, lh_actionfun *actions[], lh_value arg_results[]) |
Interleave a fixed number of strands. More... | |
lh_value | async_strand_create (lh_actionfun *action, lh_value arg, lh_exception **exn) |
Dynamically create an interleaved strand. More... | |
size_t | nodec_current_strand_count () |
Return the number of currently interleaved strands under the innermost interleaved handler. | |
lh_value | async_interleave_dynamic (lh_actionfun action, lh_value arg) |
Interleave a dynamic number of strands. More... | |
lh_value | async_timeout (lh_actionfun *action, lh_value arg, uint64_t timeout, bool *timedout) |
General timeout routine over an action . More... | |
bool | async_firstof (nodec_actionfun_t *action1, nodec_actionfun_t *action2) |
Return when the either action is done, canceling the other. More... | |
lh_value | async_firstof_ex (lh_actionfun *action1, lh_value arg1, lh_actionfun *action2, lh_value arg2, bool *first, bool ignore_exn) |
Return the value of the first returning action, canceling the other. | |
void | async_wait (uint64_t timeout) |
Asynchronously wait for timeout milli-seconds. | |
void | async_yield () |
Yield asynchronously to other strands. More... | |
Asynchronous utility functions.
#define using_cancel_scope | ( | ) |
Execute under a cancelation scope.
bool async_firstof | ( | nodec_actionfun_t * | action1, |
nodec_actionfun_t * | action2 | ||
) |
Return when the either action is done, canceling the other.
true
if the first action was finished first. void async_interleave | ( | size_t | n, |
lh_actionfun * | actions[], | ||
lh_value | arg_results[] | ||
) |
Interleave a fixed number of strands.
Interleave with arguments arg_results
. The result of each action is stored again in arg_results
; when an exception is raised, it is rethrown from interleave
once all its actions have finished. Interleave introduces a cancelation scope.
n | Number of strands to create. |
actions | Array of size n containing the action to execute for each strand. |
arg_results | Array of size n containing the argument values passed to each action and also to store the result of each action. |
lh_value async_interleave_dynamic | ( | lh_actionfun | action, |
lh_value | arg | ||
) |
Interleave a dynamic number of strands.
action | The initial action. This can use async_dynamic_spawn() to dynamically interleave more actions. |
arg | Argument passed to action. |
action
. Only returns once action
and all dynamically spawned actions are done. void async_scoped_cancel | ( | ) |
Asynchronously cancel all outstanding requests under the same cancelation scope.
This is a powerful primitive that enables cancelation of operations and for example enables timeouts over any composition of asynchronous operations. When async_scoped_cancel() is called, it cancels all outstanding (interleaved) operations under the same innermost cancelation scope (raising a cancel exception for all of them).
lh_value async_strand_create | ( | lh_actionfun * | action, |
lh_value | arg, | ||
lh_exception ** | exn | ||
) |
Dynamically create an interleaved strand.
Only works in the action
given to async_interleave_dynamic()!
lh_value async_timeout | ( | lh_actionfun * | action, |
lh_value | arg, | ||
uint64_t | timeout, | ||
bool * | timedout | ||
) |
General timeout routine over an action
.
action | The action to run. |
arg | Argument passed to action. |
timeout | The time in milli-seconds after which action is canceled. |
timedout | If not NULL, gets set whether the action timed out or not. |
action
or lh_value_null
if it timed out. void async_yield | ( | ) |
Yield asynchronously to other strands.
Equivalent to async_wait() with a 0 timeout.