Skip to content

Exposes the reject and resolve function on a Promise

Notifications You must be signed in to change notification settings

kraenhansen/promise-handle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

After 🥳 Before 😭
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.

About

Exposes the reject and resolve function on a Promise

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published