Open RealyUniqueName opened 5 years ago
Isn't this just a matter of having an additional initial state in the state machine?
Also, in your example, isn't generator
just a synchronous method that returns an object, and next
(or asyncNext
or whatever) is the actual asynchronous call?
So I looked into how Kotlin does it and it's pretty simple, I'll describe it in our terminology:
start
method that takes arguments and the final continuation. it returns Void
and immediately starts executioncreate
method which also takes arguments and the final continuation, but doesn't start the coroutine and instead of returning Void
it would return a continuation which can be called from outside to start the execution.
This proposal implies coroutines should be executed automatically at the instantiation point. However, depending on the semantics of a specific coroutine that might not be the desired behavior.
The moment to start a coroutine should be chosen by the specific coroutine implementation.