Skip to content
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

Should DDC target ES6 async / wait? #28422

Open
vsmenon opened this issue Jan 17, 2017 · 14 comments
Open

Should DDC target ES6 async / wait? #28422

vsmenon opened this issue Jan 17, 2017 · 14 comments
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. dev-compiler-async type-enhancement A request for a change that isn't a bug web-dev-compiler

Comments

@vsmenon
Copy link
Member

vsmenon commented Jan 17, 2017

V8 support landed in Chrome stable:

Chrome async functions

@vsmenon vsmenon added web-dev-compiler type-enhancement A request for a change that isn't a bug labels Jan 17, 2017
@vsmenon
Copy link
Member Author

vsmenon commented Jan 18, 2017

Related to #27315 - the JS await returns a Promise.

@vsmenon
Copy link
Member Author

vsmenon commented Jan 18, 2017

Looks like Chrome has nice support for debugging as well:

https://twitter.com/addyosmani/status/740155716401565696

@jmesserly @jacob314 do you guys think it's worth targeting this? Not clear when it'll show in other browsers.

@matanlurey
Copy link
Contributor

Since DDC is only targeting ES6, is this safe to do?

Could teams use Babel (or similar) to properly target ES5?

@jmesserly
Copy link

Since DDC is only targeting ES6, is this safe to do?

DDC is targeting whatever is supported in browsers, we're not locked in forever to the features that happened to be in ES6 (nor can we use all things in ES6 until they're supported).

Originally "browsers" meant mainly Chrome as we were replacing Dartium which was Chrome only. I don't know if at this point, we've expanded the definition of browsers. My impression is that they browsers are all pretty close together on ES support these days, though.

@jmesserly
Copy link

@jmesserly @jacob314 do you guys think it's worth targeting this? Not clear when it'll show in other browsers.

Do we think there's a big debugging benefit to Dart? When source maps are on I'm not sure users will know the difference. async/await is pretty much just a bit of syntactic sugar on top of generators, which we're already using.

@vsmenon
Copy link
Member Author

vsmenon commented Jan 19, 2017

Do we think there's a big debugging benefit to Dart?

From the twitter video, I think it would primarily be "step over" support in the debugger across await calls.

@kasperpeulen
Copy link

@matanlurey babel compiles down async festures to es5 code indeed

@vsmenon
Copy link
Member Author

vsmenon commented Feb 9, 2017

@jmesserly - if you're still looking at Node support for our tests, check out:

http://v8project.blogspot.com/2016/12/v8-nodejs.html

I.e. ,the async/await/bleeding edge bits at the bottom.

(The new dev tools support looks promising too!) V8's also added perf improvements:

http://v8project.blogspot.com/2017/02/v8-release-57.html

@jmesserly
Copy link

it may be worth seeing if #27315 can be done easily; if so that makes the code a bit cleaner (can just "await e") otherwise we'll need to do some promise->future and future->promise conversions.

@vsmenon
Copy link
Member Author

vsmenon commented Apr 27, 2017

Do we think there's a big debugging benefit to Dart? When source maps are on I'm not sure users will know the difference. async/await is pretty much just a bit of syntactic sugar on top of generators, which we're already using.

Actually, it looks like you're right - we're getting nice async/await stepping for free in Chrome 60 (canary right now). :-)

@jmesserly
Copy link

Yay! That's great news!

@jmesserly jmesserly removed their assignment May 5, 2017
@jmesserly jmesserly added Type: feature request and removed type-enhancement A request for a change that isn't a bug labels Apr 20, 2018
@jmesserly
Copy link

Current status:

Ideally we'd reconcile Future/Promise first (see #27315), as noted above. But we don't have to block on that. We're already using an adapter (from a JS generator to a Dart Future), so adapting from a Promise to a Future should be doable.

It would be easier to fix this after we switch to Kernel backend, so we don't have to implement it twice.

@munificent munificent added type-enhancement A request for a change that isn't a bug and removed Type: feature request labels Jun 22, 2018
@Markzipan
Copy link
Contributor

I have a really old CL that uses JS async/await + future/promise adapters. However, it results in some pretty annoying timing issues. Consider the following example:

import 'dart:async';

Future f() async {}

main() {
  scheduleMicrotask(() => scheduleMicrotask(() => print("third")));
  Future(() => null).then((_) => print("fourth"));
  f().then((_) => print("first"));
  scheduleMicrotask(() => print("second"));
}

Using JS promises, we get

second
third
first
fourth

Dart executes futures synchronously until the first asynchronous action (e.g., await). However, even though JS does something similar with its promises, the fact that Dart maintains an in-memory microtask queue separate from JS's means that f is starved until after the entire microtask queue is emptied. The microtask queue has no idea that JS promises are waiting to be executed (at least in my naive implementation).

@grouma
Copy link
Member

grouma commented Jun 10, 2019

Note that this change would help us to provide zero-cost async stack traces in Chrome:
https://docs.google.com/document/d/13Sy_kBIJGP0XT34V1CV3nkWya4TwYx9L3Yv45LdGB6Q/edit

With those, we likely can resolve:
dart-lang/test#1031

@vsmenon vsmenon added the area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. label Jul 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. dev-compiler-async type-enhancement A request for a change that isn't a bug web-dev-compiler
Projects
None yet
Development

No branches or pull requests

7 participants