nadako / haxe-coroutines

41 stars 5 forks source link

Executing a coroutine right away is not generic enough. #11

Open RealyUniqueName opened 5 years ago

RealyUniqueName commented 5 years ago

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.

Simn commented 4 years ago

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

Aurel300 commented 4 years ago

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?

nadako commented 3 years ago

So I looked into how Kotlin does it and it's pretty simple, I'll describe it in our terminology: