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

1.0.0 • Public • Published

async-completer

Add possibility to create promises and to complete them when we want.

Installation

$ npm install async-completer

Getting started

The usual use-case of completer is to transform a synchronous function with a callback into an async one.

In our example, we will create a synchronous function, and we'll add to it a complete object to transform it into an async one.

const foo = ...
const completer = new Completer();

foo.bar((text: String) => {
    if (text === "example") {
        completer.complete("something");
    }
});

return completer.promise;

As you can see in this example, we transformed a function with a callback into an async one. It means that it will be easier to access the data we want in our program.

Package Sidebar

Install

npm i async-completer

Weekly Downloads

41

Version

1.0.0

License

MIT

Unpacked Size

6.58 kB

Total Files

5

Last publish

Collaborators

  • julientd