NodeC  0.1
Asynchrony

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...
 

Detailed Description

Asynchronous utility functions.

Macro Definition Documentation

◆ using_cancel_scope

#define using_cancel_scope ( )

Execute under a cancelation scope.

See also
async_scoped_cancel()

Function Documentation

◆ async_firstof()

bool async_firstof ( nodec_actionfun_t action1,
nodec_actionfun_t action2 
)

Return when the either action is done, canceling the other.

Returns
true if the first action was finished first.

◆ async_interleave()

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.

Parameters
nNumber of strands to create.
actionsArray of size n containing the action to execute for each strand.
arg_resultsArray of size n containing the argument values passed to each action and also to store the result of each action.

◆ async_interleave_dynamic()

lh_value async_interleave_dynamic ( lh_actionfun  action,
lh_value  arg 
)

Interleave a dynamic number of strands.

Parameters
actionThe initial action. This can use async_dynamic_spawn() to dynamically interleave more actions.
argArgument passed to action.
Returns
The result from action. Only returns once action and all dynamically spawned actions are done.

◆ async_scoped_cancel()

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).

◆ async_strand_create()

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()!

◆ async_timeout()

lh_value async_timeout ( lh_actionfun action,
lh_value  arg,
uint64_t  timeout,
bool *  timedout 
)

General timeout routine over an action.

Parameters
actionThe action to run.
argArgument passed to action.
timeoutThe time in milli-seconds after which action is canceled.
timedoutIf not NULL, gets set whether the action timed out or not.
Returns
The result of action or lh_value_null if it timed out.

◆ async_yield()

void async_yield ( )

Yield asynchronously to other strands.

Equivalent to async_wait() with a 0 timeout.