promiseToFuture<T> function
- Object jsPromise
Converts a JavaScript Promise to a Dart Future.
@JS() external Promise<num> get threePromise; // Resolves to 3 final Future<num> threeFuture = promiseToFuture(threePromise); final three = await threeFuture; // == 3
Implementation
Future<T> promiseToFuture<T>(Object jsPromise) { final completer = Completer<T>(); final success = convertDartClosureToJS((r) => completer.complete(r), 1); final error = convertDartClosureToJS((e) => completer.completeError(e), 1); JS('', '#.then(#, #)', jsPromise, success, error); return completer.future; }
© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.13.0/dart-js_util/promiseToFuture.html