-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add Implicit Async Functions #3757
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 console Unlike the fn = (win, fail) ->
win(3)
do ->
out = 1 + await new Promise(fn) ** 2
console.log out # outputs 10 to console Similar 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? |
|
||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What’s up with all these empty lines at the end?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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! |
generatorsAreAvailable = '--harmony' in process.execArgv or | ||
'--harmony-generators' in process.execArgv | ||
files.splice files.indexOf('generators.coffee'), 1 if not generatorsAreAvailable | ||
files.splice files.indexOf('async.coffee'), 1 if not generatorsAreAvailable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.