It is not possible to initialize variables here, due to the way this macro is implemented. Furthermore, to use the variables declared in the coroutine context, you have to access them via the context variable name that was specified as parameter to CORO_END_CONTEXT, e.g. _ctx->var = 0;

If the subcontext still exists after the coroutine is invoked, it has either yielded/slept or killed itself, and so we copy the _sleep value to our own context and return (execution will continue at the case statement below, where we loop and call the coroutine again). If the subcontext is null, the coroutine ended normally, and we can simply break out of the loop and continue execution.

Parameters:

subCoro

name of the coroutine-enabled function to invoke

ARGS

list of arguments to pass to subCoro

Note:

ARGS must be surrounded by parentheses, and the first argument in this list must always be CORO_SUBCTX. For example, the regular function call myFunc(a, b); becomes the following: CORO_INVOKE_ARGS(myFunc, (CORO_SUBCTX, a, b));

This sets _sleep to -1 rather than 0 so that the context doesn't get deleted by CoroContextHolder, since we want CORO_INVOKE_ARGS to propogate the _sleep value and return immediately (the scheduler will then delete the entire coroutine's state, including all subcontexts).

Variable Documentation

This is a special constant that can be temporarily used as a parameter to call coroutine-ised methods from code that haven't yet been converted to being a coroutine, so code at least compiles correctly.

Be aware, though, that an error will occur if a coroutine that was passed the nullContext tries to sleep or yield control.