dart-completer
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

Dart Completer

npm npm

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; // => Completes after 1 second.
await completer; // => Alternative, identical syntax

With value

const completer = new Completer<string>();

setTimeout(() => {
  completer.complete("done.");
}, 1000);

const a = await completer.promise; // => "done."
const b = await completer;         // => "done."

Package Sidebar

Install

npm i dart-completer

Weekly Downloads

215

Version

2.0.0

License

MIT

Unpacked Size

21.8 kB

Total Files

16

Last publish

Collaborators

  • ciriousjoker