Dart Completer
A Typescript port of Dart's Completer.
Use it like a Promise
that you can complete from the outside.
Note that you can only complete a Completer
once, either by calling .complete()
or .completeError()
.
Subsequent calls to .complete()
or .completeError()
are ignored.
Usage
Without value
const completer = new Completer();
setTimeout(() => {
completer.complete();
}, 1000);
await completer.promise;
await completer;
With value
const completer = new Completer<string>();
setTimeout(() => {
completer.complete("done.");
}, 1000);
const a = await completer.promise;
const b = await completer;