@coffeekraken/s-promise
As simple as a native Promise, this package extends it with events capabilities using the @coffeekraken/s-event-emitter one.
Install
npm i @coffeekraken/s-promise
Promises with event capabilities
This SPromise
class workds like a normal Promise
but add the SEventEmitter
capabilities like:
emit
: emitting eventson
: subscribe to eventspipe
: pipe events to another SEventEmitter
instance- And more...
Usage
Here's how to use our implementation:
import __SPromise from '@coffeekraken/s-promise';
function myInternalProcess() {
return new __SPromise(({ resolve, reject, emit }) => {
emit('log', {
value: 'Something cool',
});
resolve();
});
}
function myStartingProcess() {
return new __SPromise(async ({ resolve, reject, emit, pipe }) => {
const promise = pipe(myInternalProcess());
promise.on('log', (data, metas) => {
});
resolve(promise);
});
}
const promise = myStartingProcess();
promise.on('log', () => {});
Settings
SPromiseSettingsInterface
-
treatCancelAs
Specify if a "cancel" event/call has to be treated like a "resolve", or like a "reject" a promise level
-
destroyTimeout
Specify after how many milliseconds the promise will be destroyed after a "finally" event
-
preventRejectOnThrow
Specify if you prefer your promise to be "resolved" when an underlying error is catched, or if is has to be rejected normally
-
emitLogErrorEventOnThrow
Specify if you want a "log" of type "error" to be emitted when an underlying error is catched
-
resolveAtResolveEvent
Specify if youw promise has to be resolved when catching a "resolve" event from deeper emitter
-
rejectAtRejectEvent
Specify if youw promise has to be rejected when catching a "reject" event from deeper emitter
-
resolveProxies
Specify some functions to be called just before resolving the promise. This function will take the current promise resolve value and must return the updated value
-
rejectProxies
Specify some functions to be called just before rejecting the promise. This function will take the current promise resolve value and must return the updated value
API
For more information about the API of this class, please check our API documentation
License
Distributed under the MIT License. See LICENSE for more information.
Contact
Here's all the ways you can contact us listed: