News for hackers. Stuff that matters.
Re:JavaScript Promises: There and back again by camus2 on Tuesday December 17, 2013 @12:54PM (#6922530)
Good but can you yield from the global scope? if not you still need to write at least a function.

The hardest stuff in JS is that :

    function F(){throw "error"}

   try{setTimeout(F,1000)}catch(error){ console.log("error")}
we cant catch async errors outside the async callback , will generators fix this ? ( by the way , that's why you should never throw any error yourself in js ).
Re:JavaScript Promises: There and back again by domenicd on Tuesday December 17, 2013 @01:30PM (#6922795)
You cannot yield from the global scope; you have to explicitly be inside a generator function. This isn't really a problem in practice except for one-off-scripts, since most modules don't have side effects but instead export functions (possibly generator functions). But for those one-off scripts it is indeed a bit awkward... you could imagine ways to get around it.

You can catch async errors with generators and promises; see e.g. the linked post, or http://jlongster.com/A-Study-on-Solving-Callbacks-with-JavaS...

Re:JavaScript Promises: There and back again by masklinn on Tuesday December 17, 2013 @02:44PM (#6923408)
> we cant catch async errors outside the async callback , will generators fix this ?

You can inject an exception into a generator via the throw method[0], and it'll be raised at the yield, as if `yield` had thrown[1].

JS exception handling facilities are still crap, though.

[0] http://wiki.ecmascript.org/doku.php?id=harmony:generators#me...

[1] http://wiki.ecmascript.org/doku.php?id=harmony:generators#in...

Re:JavaScript Promises: There and back again by coderzach on Tuesday December 17, 2013 @12:58PM (#6922565)
That's why node modules generally don't throw exceptions, but rather pass them as the first argument to the callback.

I think you can catch async errors if you call the throw method on the generator.

http://wiki.ecmascript.org/doku.php?id=harmony:generators#me...