Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add Implicit Async Functions#3757

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
GeoffreyBooth merged 47 commits intojashkenas:2fromGabrielRatener:master
Nov 2, 2016
Merged

Add Implicit Async Functions#3757

GeoffreyBooth merged 47 commits intojashkenas:2fromGabrielRatener:master
Nov 2, 2016

Conversation

GabrielRatener
Copy link
Contributor

Temporary fix for bug#3750, tried it, it works.

@GabrielRatenerGabrielRatener changed the titlechanged jison acceptable versionschange jison acceptable versionsDec 16, 2014
@GabrielRatener
Copy link
ContributorAuthor

Here is an outline of my async/await implementation:

The newawait keyword implicitly modifies an enclosing function
into an async function which returns a native JS promise when called.
The returned promise resolves to the explicit return value of the function.

When an A-compliant promise is modified withawait,
control is passed back to the calling function at that point. The async
function resumes once the function is resolved, with the value of theawait <promise> expression being that of the resolved promise.

Similar to generators, in cases where a function needs to be made async
explicitly,await return <some optional expresstion> can be used inside
the function body instead.

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
async function promises. Instead, the first non-thenable value encountered
in the promise resolution chain will be the actual resolution value of the async functions' promise. For example:

someExplicitlyAsyncFuntion=-># returns a promise that has resolution value 5awaitreturnPromise.resolve(5)do->awaitedValue=awaitsomeExplicitlyAsyncFuntion()console.log awaitedValue# logs 5 to the console

Unlike theyield operator, which can work with any kind of expression,
theawait operator, works solely on promises. Since no arithmetic operation can
result in a promise in CS/JS, theawait operator is given precedence over all arithmetic operators. For example:

fn= (win,fail)->win(3)do->out=1+awaitnewPromise(fn)**2console.log out# outputs 10 to console

Similar toyield,await cannot occur outside a function body. Additionally,
yield oryield from, andawait cannot occur in the same function body, doing so
will result in a compile time error. However in the future this may be enabled for async generators.

Any proposals, modifications, questions, or any other feedback would be really awesome!

uMaxmaxmaximus, DomVinyard, daiplusplus, rstuven, limoragni, shinout, danielbayley, and prophetw reacted with thumbs up emoji

@GabrielRatenerGabrielRatener changed the titlechange jison acceptable versionsAsync/await support on top of eneratorsDec 19, 2014
@GabrielRatenerGabrielRatener changed the titleAsync/await support on top of eneratorsAsync/await support on top of generatorsDec 19, 2014
@GabrielRatenerGabrielRatener changed the titleAsync/await support on top of generatorsAsync/await Support on Top of Generators/YieldDec 19, 2014
@vendethiel
Copy link
Collaborator

Amazing. I'm not sure the first commit should be in this PR, though.

@GabrielRatener
Copy link
ContributorAuthor

@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?





Copy link
Collaborator

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?

Copy link
ContributorAuthor

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.

@GabrielRatener
Copy link
ContributorAuthor

@vendethiel The first commit has been purged since#3750 has been fixed.

@nfour
Copy link

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I would have made anunless generatorsAreAvailable block with the twofiles.splice lines in it.

@GabrielRatener
Copy link
ContributorAuthor

Considering makingresolve an alias or possibly a replacement toawait, any thoughts?

@GabrielRatener
Copy link
ContributorAuthor

@Artazor just added support for async constructors, I think this could be quite useful, nice idea!

@Artazor
Copy link
Contributor

@GabrielRatener, great! But I think that we should scan the AST of the constructor and add the implicit return ofthis at the end, or if there are explicit returns inside the body - wrap their results with some utility like

return a# should be replaced withreturn_nonPrimitive(a,this)

where

_nonPrimitive= (value,that)->iftypeof valueis'object'        value? thatelse         that? value# ? value - for the case when constructor called as function (without new)

@lydell
Copy link
Collaborator

Looks good to me, too. Hit the green button when you feel like it,@GeoffreyBooth!

@GeoffreyBoothGeoffreyBooth merged commit496fd5d intojashkenas:2Nov 2, 2016
@GeoffreyBooth
Copy link
Collaborator

Thanks and congrats@GabrielRatener !

GabrielRatener, srb-, zeekay, lkytal, and laurentpayot reacted with hooray emoji

@GeoffreyBooth
Copy link
Collaborator

What about documentation for this?

@GabrielRatener
Copy link
ContributorAuthor

This should definitely be documented, especially since this could be a source of confusion as in#4349.

@GeoffreyBooth
Copy link
Collaborator

Do you care to write some documentation, perhaps as a new PR for2?

@GabrielRatener
Copy link
ContributorAuthor

@GeoffreyBooth Yeah, I can open a new PR for that.

GeoffreyBooth, taoeffect, and anthonylai reacted with hooray emoji

@GeoffreyBoothGeoffreyBooth modified the milestone:2.0.0Feb 9, 2017
This was referencedFeb 19, 2018
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@GeoffreyBoothGeoffreyBoothGeoffreyBooth approved these changes

@lydelllydelllydell approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
2.0.0
Development

Successfully merging this pull request may close these issues.

16 participants
@GabrielRatener@vendethiel@nfour@Artazor@Zolmeister@memelet@adambiggs@Jamesernator@zeekay@lydell@rattrayalex@GeoffreyBooth@atg@carlsmith@jashkenas@kid-wumeng

[8]ページ先頭

©2009-2025 Movatter.jp