eprom
is an enhanced promise implementation. It works by wrapping a globally available Promise
class and is as compliant with the Promises/A+ spec as the global Promise
is.
In addition to the usual then
, call
and finally
instance methods, it provides resolve
and reject
methods. In this regard, it resembles jQuery's Deferred
object. On top of that, it features a reset
method that enables repeat fulfillment.
Using NPM:
npm install -S eprom
Using Yarn:
yarn add eprom
eprom
's EnhancedPromise
mimics more usual Promises
in every way. As such, it provides all class (resolve
, reject
, all
, race
) and instance (then
, catch
, finally
) methods these provide.
This method resolves an EnhancedPromise
's inner Promise
, triggering the execution of all onFulfilled
handlers.
const enhancedPromise = new EnhancedPromise();
enhancedPromise.then(value => console.log(value));
enhancedPromise.resolve('foo');
// logs 'foo'
This method rejects an EnhancedPromise
's inner Promise
, triggering the execution of all onRejected
handlers.
const enhancedPromise = new EnhancedPromise();
enhancedPromise.catch(reason => console.err(reason));
enhancedPromise.reject('bar');
// logs 'bar'
This method creates a fresh inner Promise
and thus allows for the re-fulfillment of an EnhancedPromise
. A typical use case for this is handling repeat builds triggered by Webpack in watch mode.
const enhancedPromise = new EnhancedPromise();
enhancedPromise.then(value => console.log(value));
enhancedPromise.resolve('foo');
// logs 'foo'
enhancedPromise.reset();
enhancedPromise.then(value => console.log(value));
enhancedPromise.resolve('bar');
// logs 'bar'