-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Task advances on done() not next() ? #6125
Comments
It's because you can't tell whether a task is done without trying to run it, at which point you also get the first value it produces. |
You are also kind of breaking the contract by not checking if the iteration is |
This used to be the other way, but there was a complaint about that too. In the current arrangement, if you always call next before done the way you're supposed to, this works as one would expect. |
@StefanKarpinski I assume you intended to write "done before next"? |
Right, yes that. |
Thanks guys. OK - so the contract is to always check |
I also wondered why we need two functions (
|
Yes, that makes sense. Thanks for the explanation. It's surprisingly tricky. It still feels weird to be mutating the task within the done check. Would it make more sense to do this in
|
These definitions work fairly well:
The only downside is that they switch to the task twice before you actually get the first value. It would be nice to be able to compute the second thing that That seems to ask for |
That's exactly what I played with first… it's wonderfully simple but it seems that some other methods (like |
I don't think any other code depends on the iterator setting |
The nextval(itr,state) = next(itr,stat)[1]
nextstate(itr,state) = next(itr,stat)[2]
next(itr,state) = (nextval(itr,state), nextstate(itr,state)) These seem circular, but of course the circularity would be broken when any |
Quite true; the other side of the coin is being able to share computation between nextval and nextstate. |
It's arguable that you could just do that work twice most of the time and as long as the |
Unlike other iterable types,
Task
seem to advance ondone
instead ofnext
. Is there a reason for this - it seems to break the iteration contract. eg.Produces:
The text was updated successfully, but these errors were encountered: