-
Notifications
You must be signed in to change notification settings - Fork 27
async
/await
and Node
#7
Comments
nice job |
Going to get some people talking here since this requires attention and I think a lot of collaborators are unaware, cc @nodejs/collaborators |
Note: TC39 has been discussing, but has not formally proposed "top level await" for Modules. |
I'm -1 on adding a ES feature which is landed at v8 but not as a finished proposal. BTW, do we need to consider the https://github.com/nodejs/node-chakracore as well? |
@yorkie async functions are proposed in https://github.com/tc39/proposals and have advanced pretty far, top level await is |
@bmeck I mean the finished proposal, which has no items about async function, and the async function feature is currently in the stage 3. Let me know if I'm wrong :-) |
@yorkie Stage 3 means it is going to land, pending implementation problems / concerns for environments. That means it is the appropriate time for Node to get involved and the last chance to voice concerns before it lands in ECMA262. |
@yorkie I would prefer us not moderating language features that landed in v8 at our end. Also, most likely the proposal will be accepted (stage-4) before async functions will be enabled in v8 by default (i.e. without a flag). |
@yorkie if Node waits until the ink is dry then it has no chance to bring issues up - that has been a big pain point before. Async await already landed in ChakraCore a while ago. We need to make sure we're ready and need to expect at least some widescale adoption as this feature has seen in C#. |
@benjamingr I don't think that async-await actually requires special treatment, so the fact that it's in v8 shouldn't change anything for core
If anything, this is less important for async-await, because everything has rejection handler, except top level promise.
Nothing to decide, async functions are just functions that return promises.
Why is it needed for async-await? Try-catch is not something new.
Also not something new. I seriously doubt that someone actually monkey-patches promises to have post-mortem support.
Seems like a huge overstatement. What worst case scenario you have in mind? |
I don't think it sets a good precedent to disable features V8 has landed. We have traditionally looked to V8 to define its own stability level and take it "as is." This opens up a big can of worms and potentially endless bike shedding and second guessing of V8 which I don't think we want to get into. |
We can't "disable" this feature. Because it's not an API. It's syntax. We can not support it by not returning promises. |
People wrap our APIs in promises, including the native ones ship with. With await landing we can only expect that to increase. The burden of supporting these use cases in core, whether we return promises in core APIs or not, will increase with the increase in usage in the ecosystem and there isn't much we can do about it. |
Debating whether or not we want to support a syntax level feature is not
|
If you modify Imo the steps that would need to be taken just come around to better native promise support:
As for what we do about unhanded rejects... idk, this makes them sync like and there will be more behavior dissonance. I think we should bite the bullet and make unhandled rejects crash (by default..) in v7. Maybe we could have a way of denoting specific promises that disobey that, unsure. Perhaps we begin wrapping all modules in an async function? That way we can add a top-level catch handler and maybe make the job a bit easier on ourselves? Idk I just came up with that now so probably not. |
That will magically make |
IIUC, changing what
Unfortunately we'd have to be able to spin the microtask queue forward in order for this to work — the result of an |
|
Yes. |
Wait doesn't it require ES modules for the syntax...? |
@Fishrock123 no, what you are thinking of is top-level |
@benjamingr Source? And which version of Chrome? |
Chrome 53 Canary - windows 64 bit (without any opt-in experimental flags or custom options) has them, Chrome 51 doesn't yet. The platform status says it requires a flag but in practice it does not. |
async/await is behind |
If you override the |
@Fishrock123 it uses the intrinsic %Promise%, cannot be changed via JS : https://tc39.github.io/ecmascript-asyncawait/#abstract-ops-async-function-await |
@Fishrock123 there was a proposal that allowed overriding what This puts a lot of burden on what the platform must provide in terms of hooks and instrumentation for native promises and it means we'll have to deal with what to do on unhandled rejections better - I'm finally going to be able to work on my PR for warning next weekend which is a first step but not a solution. |
Must have not been clear enough that I responded in regards to your comment of "I don't think it sets a good precedent to disable features V8 has landed." Specifically at your use of the word "disable". I wasn't giving my stance on the topic.
Can we determine whether this is actually solvable? Since Promises must be asynchronous, and they don't differentiate between calling Are we going to question what impact this will have on the ecosystem, in terms of existing Promise implementations? Meaning, will this be the beginning of the end for libraries like bluebird? |
@targos I just converted my hobby project from Babel to native async/await and used your branch. Everything seems to just work. Thanks! |
It does |
@yorkie you probably saw async/await is stage-4 now and does exist in this list now: @targos tried out your branch, that's pretty cool that it works with the |
I'm wondering if we're better off just providing a |
@benjamingr that might be a great solution. I can imagine patterns like this in the top of my files: const promisify = require('util').promisify;
const readFileSync = promisify(require('fs').readFileSync); Not super ideal, but it's a nice utility function. Inevitably, I think people will release promisified modules (eg: Alternatively: const fs = require('fs').promisified; Could be nice, because the APIs could be exposed and stay uptodate with changes in the fs module (in this case). Just a thought, or is this too much too soon? |
Your example demonstrate a drawback of a Specifically, promisifying [Remainder of comment moved to #12] |
Closing due to lack of discussion. Feel free to reopen. |
Async/await has landed in V8, details are being worked out. This is a feature many users have been waiting for and I suspect many will use.
We need to figure out how to work with it in core, namely:
(async () => {})()
. Post-mortem core-dump users would have to run a transform on their code forbiddingasync
andawait
otherwise.I would also love to see async/await in the context of Node discussed in the next TC meeting if possible. Our window of action is rapidly closing and if there is a grave mistake we need to find it asap.
The text was updated successfully, but these errors were encountered: