-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
reconcile Future/Promise #27315
Comments
related #221 |
From @jacob314 on January 4, 2016 19:10 This is now becoming an issue for JS interop |
yeah, just wanted to add an update: this is something we're definitely doing, only question is when it happens. Probably after we've gotten the Dart language tests and modular compilation in a good place. |
and SDK issue is #24679 |
This issue has been hanging around for almost a year. Actually I first hit it here. From my understanding there has not been any work on this. I know that @alan-knight was playing some Service worker stuff (using all dart:html), but look at the repo it looks like it did not move forward, possibly because the register required handling the promise. If my assumptions above are correct? Then certainly this needs to addressed in a once and for all, promises are spreading in JS and have it map one to one with a Future in the dart2JS is reasonable. Otherwise there will be just be promise completer boilerplate all over the place. There is a type definition for es6 promises yet JS Facade Gen does not appear to handle it too well @jacob314. Hence I for one would like to this issue given some priority and clarity. |
Hit this via #28422. I'm going to see if we can do adapters in both directions:
Tricky part here is figuring out how to inject "then" and "catch" because those aren't symbolized and collide with the Dart names. Then again ... once the Future interface is marked as "may be native" we might get the renaming for free. EDIT: ah, because JavaScript Promise recognizes the mere existence of "then", we may need to use "dartx.then" on all Dart objects, kinda similar to "toString", so it doesn't pick up accidentally and be treated as a Promise "then". |
Would be nice to have this. |
If/when dart compilers get native support of JS Promises, please don't tie it to FWIW, we're using the following boilerplate which works mostly fine both in browsers and node: @JS()
class Promise<T> {
external Promise(void executor(void resolve(T result), Function reject));
external Promise then(void onFulfilled(T result), [Function onRejected]);
} To create a return new Promise<MyType>(allowInterop((resolve, reject) {
myFuture.then(resolve, onError: reject);
})); To create a final completer = new Completer<MyType>();
myPromise.then(allowInterop(completer.complete),
allowInterop(completer.completeError));
return completer.future; |
|
It is promising! sdk/sdk/lib/_internal/js_dev_runtime/lib/js_util/dart2js/js_util_dart2js.dart Lines 132 to 150 in a577d0a
|
any news on this? would be awesome to be able to await a promise without having to use |
From @jmesserly on June 25, 2015 20:50
For JS interop, it would be ideal if we could adapt Dart Futures to implement the Promise interface.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
This will also ease DOM interop as Promise becomes more common.
Ideally, Dart Future actually is a JS Promise, simply exposing different user-facing APIs (similar to Dart builtin List type and JS Array). But we could also try adapters, similar to Dart Iterable objects exposing a
[Symbol.iterator]()
method to JS, and Dart for-each consuming JS Iterables.Copied from original issue: dart-archive/dev_compiler#245
The text was updated successfully, but these errors were encountered: