completerForPromise<T> function

Completer<T> completerForPromise<T>(
  1. Promise promise
)

Creates a completer for the given JS promise.

Implementation

Completer<T> completerForPromise<T>(Promise promise) {
  Completer<T> out = Completer();

  // Create interopts for promise
  promise.then(allowInterop((value) {
    out.complete(value);
  }), allowInterop(([value]) {
    out.completeError(value, StackTrace.current);
  }));

  return out;
}