-
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
CS2 Discussion: Features: async/await #4908
Comments
Migrated from coffeescript6/discuss#10 (comment) Implicit async if await is detected in the method body +1 |
Migrated from coffeescript6/discuss#10 (comment) Agree with @DomVinyard on this one. This is what IcedCoffeeScript is doing. |
Migrated from coffeescript6/discuss#10 (comment) Why can't we just use syntax with |
Migrated from coffeescript6/discuss#10 (comment) Ah, |
Migrated from coffeescript6/discuss#10 (comment) @rattrayalex i think if we were trying to mess with 'await' as a keyword, the only sensible 'true coffeescript' approach would be to go the other way and make it the more verbose 'wait for', rather than trying to get people to memorise a new operator.
But that has a whole bunch of issues, not least of all the overloading on the word 'for'. Personally think should be left untouched.
Is such a wonderful reminder of how far JS has come, isn't it. |
Migrated from coffeescript6/discuss#10 (comment) Personally, I find the fn() ->
res = await fetch('url')
await res.json() What about something like this instead: fn() ->
res <= fetch('url')
<- res.json() Where Thoughts? |
Migrated from coffeescript6/discuss#10 (comment) Basic support is shipping in several browsers: tc39/proposal-async-await#97 (comment) |
Migrated from coffeescript6/discuss#10 (comment) @octet-stream why does Note also this would prevent Slightly OT, but I also believe the |
Migrated from coffeescript6/discuss#10 (comment) async functions don't necessarily contain async function () {
return Promise.resolve(1)
} ... but, they also don't need the async keyword. So I think I support implicit |
Migrated from coffeescript6/discuss#10 (comment) I am leaning in the direction of leaving In a world with a |
Migrated from coffeescript6/discuss#10 (comment)
amen, brother. and
Yeah, absolutely. +1 here. |
Migrated from coffeescript6/discuss#10 (comment) I'm not sure, but how about adding these operators as aliases for Koa = require 'koa'
koa = new Koa
async koa.use (ctx, next) ->
ctx.body = 'Hello, world!'
await do next
koa.listen 2319, -> console.log 'Koa started on http://localhost:2319' or Koa = require 'koa'
koa = new Koa
koa.use (ctx, next) ~>
ctx.body = 'Hello, world!'
<~ do next
koa.listen 2319, -> console.log 'Koa started on http://localhost:2319' |
Migrated from coffeescript6/discuss#10 (comment) To elaborate, the async -> await bar() which looks like you're doing this: async(function(){ await bar(); }); which you're not. CoffeeScript's two-character function definitions enable more expressive, functional programming styles, and make JavaScript (arguably) more readable and (absolutely) more lightweight. Requiring use of the Most importantly, whether or not a function is asynchronous can be inferred by whether it contains an The one reason one might want to include |
Migrated from coffeescript6/discuss#10 (comment) As for "why introduce new syntax for So code that used to look like this: foo() ->
fetch(someUrl)
.then resp ->
resp.json()
.then json ->
someTransform(json) can now look like this: foo() ->
resp = await fetch(someUrl)
json = await resp.json()
someTransform(json) or, better yet: foo() ->
resp <- fetch(someUrl)
json <- resp.json()
someTransform(json) ... which has a substantial keystroke savings, is arguably more clear/readable, and doesn't look like a function call. In general, CoffeeScript is very light on keywords, which is great because function calls look like keywords. |
Migrated from coffeescript6/discuss#10 (comment) Also, is there anything we lose by not supporting this feature? Any JavaScript library or framework that can’t be used because we can’t do I noticed that |
Migrated from coffeescript6/discuss#10 (comment) @octet-stream verbosity. 😉 |
Migrated from coffeescript6/discuss#10 (comment) Use facebook regenerator if you want working example :) |
Migrated from coffeescript6/discuss#10 (comment) I’m working on the document that puts in one place our consensus plans. To confirm that I’m understanding this correctly:
So to take the example from http://stackabuse.com/node-js-async-await-in-es7/, this JavaScript: var request = require('request-promise');
async function main() {
var body = await request.get('https://api.github.com/repos/scottwrobinson/camo');
console.log('Body:', body);
}
main(); would be written in CoffeeScript as: request = require 'request-promise'
main = ->
body = await request.get 'https://api.github.com/repos/scottwrobinson/camo'
console.log 'Body:', body
main() ? I think using |
Migrated from coffeescript6/discuss#10 (comment) Yes, I think we can implicit |
Migrated from coffeescript6/discuss#10 (comment)
Other than the fact that Thoughts? |
Migrated from coffeescript6/discuss#10 (comment) @zeekay pointed out this PR which seems to be exactly what we want to implement, though it should be revised to remove the ES5 shim. Based on the precedent of generators and modules, I think our consensus now is that ESNext features are output as ESNext, especially if they’re opt-in by using a special syntax. But this feature may be very close to implementation based on the work in the PR. |
Migrated from coffeescript6/discuss#10 (comment) Prefer implicit
|
Migrated from coffeescript6/discuss#10 (comment)
I'm just used sayHello = (name = 'Nick') -> console.log "Hello, #{name}!"
do sayHello # -> Hello, Nick!
sayHello "Alex" # -> Hello, Alex! I think this code looks more pretty than
Maybe just for alternative asynchronous function declaration syntax? |
Migrated from coffeescript6/discuss#10 (comment) I would definitely go for a simple function declaration as before. First, as said before it matches the way CoffeeScript manages generator (inference from the yield usage). Second, it will not require you to care about removing Oh, and concerning |
Migrated from coffeescript6/discuss#10 (comment)
It reached stage 4 a few months ago: https://github.com/tc39/proposals/blob/master/finished-proposals.md . So all of the details have been finalized and it will be in ES2017. My guess is that the "Debatable Syntax & Semantics" part of the page you linked is just out of date. |
Migrated from coffeescript6/discuss#10 (comment) Sure, but please review what’s already been built so far regarding |
Migrated from coffeescript6/discuss#10 (comment) One question. Is there ever a reason that developer would call an async function without await? Because if there is not one, then we could really easily do something where we mark a function as async, which would do two things:
So what I would like from CoffeeScript is to make all this magical. So maybe we could have:
Observe Here, a good thing is that a return value of the Promise's Now, I dislike the fact that we have to write
So because Alternatively, we could do (a list of different syntaxes):
(Here Alternative:
Or:
BTW, I think just having |
Migrated from coffeescript6/discuss#10 (comment)
Ah, silly me. Thanks.
What's wrong with just |
Migrated from coffeescript6/discuss#10 (comment) Sorry forgot to close this. This feature has been implemented. |
Migrated from coffeescript6/discuss#10 (comment) Hm, OK, but what about discussion about making async/await more integrated with the language? Should I open another issue for that? |
From @mitar on Dec 11, 2016 If I understand, currently there is only |
From @mitar on Dec 11, 2016 I opened coffeescript6/discuss#60. |
Migrated from coffeescript6/discuss#10
Originally created by @rattrayalex on Sat, 23 Jul 2016 02:54:17 GMT
The syntax here could be quite tricky, and the feature is pretty important. This could be an opportunity for CoffeeScript to offer dramatically nicer syntax than ES6 for a core feature.
Let's discuss anything related to async/await here.
The text was updated successfully, but these errors were encountered: