haxe-coroutines
haxe-coroutines copied to clipboard
Executing a coroutine right away is not generic enough.
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.
var g = generator(); //instantiation
g.configure(options);
for(item in g) { //execution
trace(item);
}
The moment to start a coroutine should be chosen by the specific coroutine implementation.
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:
- what we have in the proposal right now is the
start
method that takes arguments and the final continuation. it returnsVoid
and immediately starts execution - what we can have in addition is the
create
method which also takes arguments and the final continuation, but doesn't start the coroutine and instead of returningVoid
it would return a continuation which can be called from outside to start the execution.