<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Dec 19, 2012 at 1:24 AM, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>></span> wrote:<br>
<br></div><div class="gmail_quote">... snip ...<br><br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>That looks reasonable too, although the signature may need to be adjusted. (How does it cancel the remaining tasks if it wants to? Or does par() do that if this callback raises?) maybe call it filter?</div>

<div></div></blockquote><div><br></div><div>The subtask completion callback can call abort() on the overall par_task, which could cancel the rest of the unfinished tasks.<br><br></div><div>    def abort_task(par_task, subtask):<br>
</div><div>        try:<br>            return subtask.result()<br></div><div>        except ValueError:<br></div><div>            par_task.abort()<br><br>The issue with this approach is that since the par() would return values again, not tasks, we'd can't handle errors locally. Futures are also immutable, so we can't modify the values after they resolve. Maybe we'd have something like:<br>
<br></div><div>    def fail_silently(par_task, subtask):<br></div><div>        try:<br></div><div>            subtask.result()<br></div><div>        except ValueError as e:<br></div><div>            return Future.completed(None) # an already completed future that has a value of None, sorry, don't remember the exact spelling<br>
</div><div>        else:<br></div><div>            return subtask<br><br></div><div>which allows us:<br><br></div><div>    for task in par(*tasks, subtask_completion=fail_silently):<br>        # ...<br><br></div><div>Which allows us both local error handling, as well as batch error handling. But it's very verbose from the side of the callback. Hm.<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>But what did you think of my wait_one() proposal? It may work beter in a coroutine, where callbacks are considered a nuisance.</div>
</blockquote><div><br></div><div>To be honest, I didn't quite understand it. I'd have to go back and re-read PEP 3148.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div class="gmail_quote">I like the initial approach, but the details need fleshing out. I think it would be neat if we could have several standard behaviors in the stdlib: subtask_completed=fail_silently, subtask_completed=abort_task, etc.<br>


</div><div class="gmail_quote"><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>
> And, of course, we should make sure that we can handle the four situations<br>
> mentioned in [0] , even if we don't solve them with callbacks.<br>
><br>
> [0] <a href="https://gist.github.com/3889970" target="_blank">https://gist.github.com/3889970</a><br>
<br>
</div>That's longwinded and written in a confrontational style. Can you summarize?<br></blockquote><div><br></div><div>Yeah, this was more at a lament at libraries like jQuery that implement the CommonJS Promise/A specification wrong. It's really only relevant if we choose to add errbacks, as it's about the composition and sematics between callbacks/errbacks, and chaining the two.</div>

</div></div></div></div></blockquote><div><br></div></div><div>No, no, no! Please. No errbacks. No chaining. Coroutines have a different way to spell those already: errbacks -> except clauses, chaining -> multiple yield-froms in one coroutine, or call another coroutine. Please.</div>
<span class="HOEnZb"><font color="#888888">
<div><br></div></font></span></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="HOEnZb"><font color="#888888"><div>--Guido<span></span> </div><br>
<br>-- <br>--Guido van Rossum (on iPad)<br>
</font></span></blockquote></div><br><br clear="all"><br>-- <br>  Jasper<br><br>
</div></div>