0.1.0 • Published 6 months ago

promise-handle v0.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

Promise Handle 🤌

The PromiseHandle exported from this package extends the Promise class to expose the resolve and reject functions passed through the constructor as member functions.

Here's a few examples on how to use the promise-handle package.

import { PromiseHandle } from "promise-handle";
const handle = new PromiseHandle();
emitter.on("even", handle.resolve);
await handle;
await new Promise((resolve) => {
  emitter.on("even", (event) => {
    resolve(event);
  });
});
import { PromiseHandle } from "promise-handle";
const handle = new PromiseHandle();
await something({
  callback() {
    handle.resolve();
  }
});
await handle;
let inner;
const callback = new Promise((resolve) => {
  inner = something({
    callback() {
      resolve();
    }
  });
});
await inner;
await callback;

But why? 🤷

I've written and added this small utility class into five code-bases already and I thought I might as well get it into the NPM registry to get it handy next time around.

0.1.0

6 months ago