Generator return() and exceptions

Nathan Wall wwall at google.com
Thu Jul 24 10:38:02 PDT 2014


Allen Wirfs-Brock wrote:
> So going back to my original questions. Given that we now have return()
> available to close an abnormally discarded generator, when would somebody
> (presumably implementing a control abstraction) actually want to apply
> throw() rather than return() to an iterator?

Sorry, I may be misunderstanding, but what about the use from Task.js?

https://github.com/mozilla/task.js/blob/master/lib/task.js#L395

```
var foo = async(function*() {
    throw 'from foo';
});

var bar = async(function*() {
    var promise = foo(),
        value;
    try {
        value = yield promise;
    } catch (e) {
        console.log(e);
    }
});
```

The above should log "from foo".  Wouldn't `throw()` be needed for that?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140724/232eb5aa/attachment-0001.html>


More information about the es-discuss mailing list