Add Implicit Async Functions#3757
Add Implicit Async Functions#3757GeoffreyBooth merged 47 commits intojashkenas:2from GabrielRatener:master
Conversation
|
Here is an outline of my async/await implementation: The new When an A-compliant promise is modified with Similar to generators, in cases where a function needs to be made async When an awaited promise is rejected, a regular error is thrown. These errors can be handled like any other, with try/catch statements. Since native ES6 promises cannot resolve to a promise, neither can someExplicitlyAsyncFuntion = ->
# returns a promise that has resolution value 5
await return Promise.resolve(5)
do ->
awaitedValue = await someExplicitlyAsyncFuntion()
console.log awaitedValue # logs 5 to the consoleUnlike the fn = (win, fail) ->
win(3)
do ->
out = 1 + await new Promise(fn) ** 2
console.log out # outputs 10 to consoleSimilar to Any proposals, modifications, questions, or any other feedback would be really awesome! |
|
Amazing. I'm not sure the first commit should be in this PR, though. |
|
@vendethiel CS does not work properly with newer versions of Jison, see #3750. Until CS is updated to work with a newer version of Jison, shouldn't only v0.2.x be used? |
test/async.coffee
Outdated
There was a problem hiding this comment.
What’s up with all these empty lines at the end?
There was a problem hiding this comment.
@lydell Not sure, but I want to make the last test more specific anyway, so I will eliminate this in the next commit.
|
@vendethiel The first commit has been purged since #3750 has been fixed. |
|
SIgn me up, the more control flow options the better at this point! |
Cakefile
Outdated
There was a problem hiding this comment.
I would have made an unless generatorsAreAvailable block with the two files.splice lines in it.
|
Considering making |
|
@Artazor just added support for async constructors, I think this could be quite useful, nice idea! |
|
@GabrielRatener, great! But I think that we should scan the AST of the constructor and add the implicit return of return a
# should be replaced with
return _nonPrimitive(a, this)where _nonPrimitive = (value, that) ->
if typeof value is 'object'
value ? that
else
that ? value # ? value - for the case when constructor called as function (without new) |
|
Looks good to me, too. Hit the green button when you feel like it, @GeoffreyBooth! |
|
Thanks and congrats @GabrielRatener ! |
|
What about documentation for this? |
|
This should definitely be documented, especially since this could be a source of confusion as in #4349. |
|
Do you care to write some documentation, perhaps as a new PR for |
|
@GeoffreyBooth Yeah, I can open a new PR for that. |
Temporary fix for bug #3750, tried it, it works.