Reference¶
Signatures¶
-
BlockLambda
(auto &context, auto &variables)¶ Lambda that is passed to
stackless_coroutine::make_block
orstackless_coroutine::make_while_true
Parameters: - context –
stackless_coroutine::context_type
- variables – A reference to the coroutine variables class for this coroutine
- context –
-
FirstBlockLambda
(auto &context, auto &variables, auto&&... coroutine_parameters)¶ First lambda that is passed to
stackless_coroutine::make_block
Parameters: - context –
stackless_coroutine::context_type
- variables – A reference to the coroutine variables class for this coroutine
- coroutine_parameters – Parameters that are passed to the coroutine
- context –
-
BlockLambdaAfterAsync
(auto &context, auto &variables, auto&&... async_handler_parameters)¶ Lambda that follows a call to a async function
Parameters: - context –
stackless_coroutine::context_type
- variables – A reference to the coroutine variables class for this coroutine
- parameters – Parameters that are passed to the async handler
- context –
-
CoroutineCompletionFunction
(auto &variables, std::exception_ptr ep, stackless_coroutine::operation op)¶ Lambda or function that is passed in to
make_coroutine
and is called exactly once upon completion of the coroutineParameters: - variables – A reference to the coroutine variables class for this coroutine
- ep – An exception_ptr that has any exception that escaped a
BlockLambda
. If no exception occurred, will be empty - op –
Enumeration of
stackless_coroutine::operation
which tells how the coroutine finishedstackless_coroutine::_done
- Coroutine finished via exiting the lastBlockLambda
without any exceptionsstackless_coroutine::_return
- Coroutine finished viacontext.do_return()
orcontext.do_async_return()
. This indicates an early return.stackless_coroutine::_exception
- Coroutine finished via an exception that escaped aBlockLambda
. The exception will be inep
.
Functions¶
All functions mentioned are in namespace stackless_coroutine
-
template<class ...
BlockFunction
>
automake_block
(BlockFunction&&... blockfunctions)¶ Makes a block which is analogous to a block or compound statement in C++. This consists of a sequence of BlockFunctions
Parameters: blockfunctions – Sequence of BlockFunctions
Returns: Returns a block which then may be passed to make_coroutine
-
template<class
CoroutineVariables
, classBlock
, classCoroutineCompletionFunction
, class ...ConstructorArguments
>
automake_coroutine
(Block block, CoroutineCompletionFunction f, ConstructorArguments&&... arguments)¶ Makes a coroutine.
Parameters: - block – block created by call to
make_block
- f –
CoroutineCompletionFunction
which will be called when coroutine finishes - arguments – Arguments to the construct of
CoroutineVariables
Returns: Returns a coroutine.
- block – block created by call to
-
template<class ...
BlockFunction
>
automake_while_true
(BlockFunction&&... blockfunctions)¶ Makes the equivalent of
while(true){...}` ``blockfunctions
will be executed repeatedly until one of the follow happens- Call to
context.do_return
- Call to
context.do_async_return
- An exception escapes a
BlockLambda
Parameters: blockfunctions – Sequence of BlockFunctions
Returns: Returns a BlockLambda
functor which may be used anywhere aBlockLambda
is used. This allowsmake_while_true
to be nested- Call to
Classes¶
All functions mentioned are in namespace stackless_coroutine
-
class
context_type
¶ This is more a concept than a class. This is the type of
context
inBlockLambda
-
template<class ...
T
>
voidoperator()
(T&&... t)¶ This will call the
BlockLambdaAfterAsync
passingt
as the arguments aftercontext
andvariables
Note this is only available if theBlockLambda
hasreturn context.do_async()
-
operation
do_return
()¶ Does an early return from the coroutine
-
async_result
do_async_return
()¶ Same as
do_return
, but used in aBlockLambda
that callscontext.do_async()
in one or more branches of the lambda
-
operation
do_break
()¶ Analogous to
break
Breaks out of amake_while_true
loop
-
async_result
do_async_break
()¶ Same as
do_break
, but used in aBlockLambda
that callscontext.do_async()
in one or more branches of the lambda
-
operation
do_continue
()¶ Analogous to
continue
Goes to the top of amake_while_true
loop
-
async_result
do_async_continue
()¶ Same as
do_continue
, but used in aBlockLambda
that callscontext.do_async()
in one or more branches of the lambda
-
operation
do_next
()¶ Goes to next
BlockLambda
in the sequence
-
async_result
do_async
()¶ Signals to stackless_coroutine that an async function with
context
as the callback has been called. The coroutine will be suspended until the async function callscontext
resulting in theBlockLambdaAfterAsync
(theBlockLambda
following thisBlockLambda
) being called with the arguments the async function passed to the callback
-
static coroutine_context_t
get_context
(void *v)¶ Creates a
coroutine_context_t
fromvoid*
which points to thevariables
passed toBlockLamda
. The purpose of this static function is to enable easy interop with legacy C functions that take a function pointer and avoid*
that will be passed to the function callback
-
template<class ...