Carrack
Installation
$ npm install carrack --save
API
AsyncEmitter
extends EventEmitter
class .emitParallel(event[, arg1, arg2...])
-> Promise<values>
run the listeners in parallel using Promise.all.
; ; // ['bar', 'bar']
in addition, exceptions and rejects, the first one is thrown.
; // [Error: beep]
.emitSerial(event[, arg1, arg2...])
-> Promise<values>
run the listeners in serial. if listener returned the exception, will not be executed later listener.
; // [ // 1460566000100, // 1460566000200, // 1460566000300 // ] ;// bar// Unhandled rejection abort
.emitReduce(event[, arg1, arg2...])
/ .emitReduceRight
-> Promise<value>
run the listener in serial using return value of the previous listener. the last return value is always an array.
const emitter = ; emitter ; emitter ;
.setConcurrency(max)
to limit the maximum number of concurrent execution of the listener of this instance.
this limit applies to the above-mentioned ".emit*" method (doesn't apply to .emit
).
async { const delayListener = { ; }; const emitter = 1 // first argument `.setConcurrency` alias ; console; // [ 1464602000100, // 1464602000200, // 1464602000300, // 1464602000400, // 1464602000500 ] console; // [ 1464602000600, // 1464602000600, // 1464602000700, // 1464602000700, // 1464602000800 ] console; // [ 1464602000800, // 1464602000800, // 1464602000800, // 1464602000800, // 1464602000800 ]};
.subscribe(event, listener, once = false)
=> unsubscribe()
alias for emitter.on
and emitter.removeListener
.
makes it easy to remove the listener when needed.
// ...const emitter = ; Component { thisunsubscribes = ; thisunsubscribes; thisunsubscribes; thisunsubscribes; } { thisunsubscribes; }