give-promise
A simple wrapper around Promise
providing a more human-friendly interface
What it does
Wraps this:
let resolve let reject const promise = { resolve = innerResolve; reject = innerReject; };
So that you can do this:
const givePromise = const promise resolve reject =
But ESM
Here you go:
If you use a module bundler like webpack
or rollup
, you can point 'give-promise'
to 'give-promise/index.mjs'
and then do this:
See your bundler's docs for how to setup that redirect, should be simple.
Raison d'être
Personally, I don't like the default interface of Promise
. Needing to wrap my code inside a constructor just seems bad to me. I found myself doing the above extraction quite frequently and therefore decided to put that into a neat little helper.
With this, you can pass around the promise and its related resolve and reject functions quite easily and intuitively.