haxe-coroutines icon indicating copy to clipboard operation
haxe-coroutines copied to clipboard

Executing a coroutine right away is not generic enough.

Open RealyUniqueName opened this issue 5 years ago • 3 comments

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.

RealyUniqueName avatar Sep 16 '18 20:09 RealyUniqueName

Isn't this just a matter of having an additional initial state in the state machine?

Simn avatar Aug 16 '20 07:08 Simn

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?

Aurel300 avatar Aug 16 '20 08:08 Aurel300

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 returns Void 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 returning Void it would return a continuation which can be called from outside to start the execution.

nadako avatar Feb 12 '21 02:02 nadako