Coroutine related boilerplate and wrappers.
Bases: object
A threadlocal-like object that works in the context of coroutines. That means, the current running coroutine has the _ident_.
Coroutine.run_op sets the indent before running a step and unsets after.
Example:
loc = local()
loc.foo = 1
The loc instance’s values will be different for separate coroutines.
Bases: cogen.core.events.Operation
We need a coroutine wrapper for generators and functions alike because we want to run functions that don’t return generators just like a coroutine, also, we do some exception handling here.
Handle the operation:
Return self is used as a optimization. Coroutine is also a Operation which handles it’s own completion (resuming the caller and the waiters).