Node-js EventEmitter helpers
npm install node-on
(...events: string[]) => (callback: (val: any) => void) => (...emitters: EventEmitter[]) => () => void
import { on } from 'node-on'
// we have the following emitters
declare const e0: EventEmitter,
e1: EventEmitter
const observer = on(
'data',
'end' // events to listen
)(
(value: any) => {} // your callback
)
const unsub = observer(
e0,
e1 // subscribe to emitters
) // return unsubscribe function
// unsubscribe
unsub()
(...events: string[]) => (callback: (val: {value: any, event: string, index: number, emitterIndex: number, emitter: EventEmitter}) => void) => (...emitters: EventEmitter[]) => () => void
import { onEx } from 'node-on'
// we have the following emitters
declare const e0: EventEmitter,
e1: EventEmitter
const observer = onEx(
'data',
'end' // events to listen
)(
({ value, event, index, emitterIndex, emitter }) => {} // your callback
)
const unsub = observer(e0, e1) // subscribe to emitters, return unsubscribe function
// unsubscribe
unsub()
(...events: string[]) => (callback: (values: any[]) => void) => (...emitters: EventEmitter[]) => () => void
import { onceAll } from 'node-on'
// we have the following emitters
declare const e0: EventEmitter,
e1: EventEmitter
const observer = onceAll(
'data',
'end' // events to listen
)(
(values: any[]) => {} // your callback
)
const unsub = observer(e0, e1) // subscribe to emitters, return unsubscribe function
// unsubscribe
unsub()
(...events: string[]) => (callback: (val: { value: any, event: string, index: number, emitter: EventEmitter, emitterIndex: number }) => void) => (...emitters: EventEmitter[]) => () => void
import { onceAll } from 'node-on'
// we have the following emitters
declare const e0: EventEmitter,
e1: EventEmitter
const observer = onceAll(
'data',
'end' // events to listen
)(
({ value, event, index, emitter, emitterIndex }) => {} // your callback
)
const unsub = observer(e0, e1) // subscribe to emitters, return unsubscribe function
// unsubscribe
unsub()
(...events: string[]) => (...emitters: EventEmitter[]) => Promise<any[]>
import { onceAllPromise } from 'node-on'
// we have the following emitters
declare const e0: EventEmitter,
e1: EventEmitter
onceAllPromise(
'data', // events to listen
)(
e0,
e1
).then(([valueFromEmitter0, valueFromEmitter1]) => {
// your callback
})
(...events: string[]) => (...emitters: EventEmitter[]) => Promise<{ value: any, event: string, index: number, emitter: EventEmitter, emitterIndex: number }[]>
import { onceAllPromise } from 'node-on'
// we have the following emitters
declare const e0: EventEmitter,
e1: EventEmitter
onceAllPromise(
'data' // events to listen
)(
e0,
e1
).then(([emitterExValue0, emitterExValue1]) => {
// your callback
})
(rejectEvents: string[], resolveEvents: string[]) => (...emitters: EventEmitter[]) => Promise<any[]>
import { onceAllPromise } from 'node-on'
// we have the following emitters
declare const e0: EventEmitter,
e1: EventEmitter
onceAllPromise(['error'], ['data'])(
e0,
e1
).then(([ valueFromEmitter0, valueFromEmitter1 ]) => {
// your callback
}).catch((error: any) => {
// your error handler
})
(rejectEvents: string[], resolveEvents: string[]) => (...emitters: EventEmitter[]) => Promise<{ value: any, event: string, index: number, emitter: EventEmitter, emitterIndex: number }[]>
import { onceAllPromise } from 'node-on'
// we have the following emitters
declare const e0: EventEmitter,
e1: EventEmitter
onceAllPromise(['error'], ['data'])(
e0,
e1
).then(([ valueExFromEmitter0, valueExFromEmitter1 ]) => {
// your callback
}).catch(({ value, event, index, emitterIndex, emitter }) => {
// your error handler
})
(...events: string[]) => (callback: (val: any) => void) => (...emitters: EventEmitter[]) => () => void
import { onceRace } from 'node-on'
// we have the following emitters
declare const e0: EventEmitter,
e1: EventEmitter
const observer = onceRace(
'data',
'end' // events to listen
)(
(value: any) => {} // your callback
)
const unsub = observer(
e0,
e1 // subscribe to emitters
) // return unsubscribe function
// unsubscribe
unsub()
(...events: string[]) => (callback: (val: { value: any, event: string, index: number, emitterIndex: number, emitter: EventEmitter }) => void) => (...emitters: EventEmitter[]) => () => void
import { onceRace } from 'node-on'
// we have the following emitters
declare const e0: EventEmitter,
e1: EventEmitter
const observer = onceRace(
'data',
'end' // events to listen
)(
({ value: any, emitterIndex: number, emitter: EventEmitter }) => {} // your callback
)
const unsub = observer(
e0,
e1 // subscribe to emitters
) // return unsubscribe function
// unsubscribe
unsub()
(...events: string[]) => (...emitters: EventEmitter[]) => Promise<any>
import { onceRacePromise } from 'node-on'
// we have the following emitters
declare const e0: EventEmitter,
e1: EventEmitter
onceRacePromise(
'data',
'end' // events to listen
)(
e0,
e1 // subscribe to emitters
).then((value: any) => {
// your callback
})
(...events: string[]) => (...emitters: EventEmitter[]) => Promise<{ value: any, event: string, index: number, emitterIndex: number, emitter: EventEmitter }>
import { onceRaceExPromise } from 'node-on'
// we have the following emitters
declare const e0: EventEmitter,
e1: EventEmitter
onceRacePromiseEx(
'data',
'end' // events to listen
)(
e0,
e1 // subscribe to emitters
).then(({ value, event, index, emitterIndex, emitter }) => {
// your callback
})
(...events: string[]) => (...emitters: EventEmitter[]) => Promise<any>
import { onceRacePromiseReject } from 'node-on'
// we have the following emitters
declare const e0: EventEmitter,
e1: EventEmitter
onceRacePromise(['error'], ['data'])(
e0,
e1 // subscribe to emitters
).then((value: any) => {
// your callback
}).catch((error: any) => {
// error handler
})
(...events: string[]) => (...emitters: EventEmitter[]) => Promise<{ value: any, event: string, index: number, emitterIndex: number, emitter: EventEmitter }>
import { onceRaceExPromiseReject } from 'node-on'
// we have the following emitters
declare const e0: EventEmitter,
e1: EventEmitter
onceRacePromiseEx(['error'], ['data'])(
e0,
e1 // subscribe to emitters
).then(({ value, event, index, emitterIndex, emitter }) => {
// your callback
}).catch(({ value, event, index, emitterIndex, emitter }) => {
// error handler
})