eventemitter2
semver
>=6.0.0postconditions12functions6last verified2026-04-16coverage score100%Postconditions — what we check
- EventEmitter2 · eventemitter2-001errorWhenerror event emitted without listenerThrows
Uncaught exception unless ignoreErrors configuredRequired handlingCaller MUST attach error event listenercostmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[1] - emit · eventemitter2-emit-unhandled-errorerrorWhenerror event emitted with no listener and ignoreErrors: false (default)Throws
Error — either re-throws the emitted Error instance or throws new Error("Uncaught, unspecified 'error' event.")Required handlingCaller MUST attach .on('error', handler) before emitting error events, or pass ignoreErrors:true to the constructorcostmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[2] - emitAsync · eventemitter2-emit-async-unhandled-errorerrorWhenemitAsync('error', err) called with no 'error' listener registered and ignoreErrors: falseThrows
Returns Promise.reject(err) — a rejected Promise with the error or a string messageRequired handlingCaller MUST attach .on('error', handler) OR wrap emitAsync() in try/catch or .catch()costmediumin proddelayed failureusers seedegraded performancevisibilitysilentSources[2] - emitAsync · eventemitter2-emit-async-listener-rejectionwarningWhenany registered listener throws or returns a rejected PromiseThrows
Returns rejected Promise with the first listener's rejection reason (Promise.all semantics)Required handlingCaller MUST await emitAsync() and wrap in try/catch, or chain .catch()costlowin proddelayed failureusers seedegraded performancevisibilitysilent - waitFor · eventemitter2-wait-for-timeoutwarningWhentimeout option is > 0 and the event is not emitted within that durationThrows
Rejects with Error('timeout') — the rejection message is literally 'timeout'Required handlingCaller MUST wrap waitFor() in try/catch or .catch() when using timeout optioncostlowin proddelayed failureusers seedegraded performancevisibilitysilentSources[2] - waitFor · eventemitter2-wait-for-cancelwarningWhenpromise.cancel() is called before the event firesThrows
Rejects with Error('canceled')Required handlingCaller MUST handle rejection if cancel() can be called on in-flight promisescostlowin proddelayed failureusers seedegraded performancevisibilitysilentSources[2] - waitFor · eventemitter2-wait-for-handle-errorwarningWhenhandleError: true in options AND the event fires with a truthy first argumentThrows
Rejects with the first argument as the error reasonRequired handlingCaller MUST wrap in try/catch when handleError option is enabledcostlowin proddelayed failureusers seedegraded performancevisibilitysilent - EventEmitter2.once · eventemitter2-static-once-error-rejectionerrorWhenthe emitter emits 'error' before the target event firesThrows
Rejects with the error emitted — the rejection reason is the Error object from the error eventRequired handlingCaller MUST wrap EventEmitter2.once() in try/catch or chain .catch()costmediumin proddelayed failureusers seedegraded performancevisibilitysilentSources[2] - EventEmitter2.once · eventemitter2-static-once-timeoutwarningWhentimeout option is > 0 and the event does not fire within that durationThrows
Rejects with Error('timeout')Required handlingCaller MUST wrap in try/catch or .catch() when using timeout optioncostlowin proddelayed failureusers seedegraded performancevisibilitysilentSources[2] - EventEmitter2.once · eventemitter2-static-once-cancelwarningWhenpromise.cancel() is called before the event firesThrows
Rejects with Error('canceled')Required handlingCaller MUST handle rejection if cancel() can be called on in-flight promisescostlowin proddelayed failureusers seedegraded performancevisibilitysilentSources[2] - listenTo · eventemitter2-listen-to-invalid-targeterrorWhentarget parameter is not an object, or target does not implement addEventListener/on/addListenerThrows
TypeError('target musts be an object') or Error('target does not implement any known event API')Required handlingCaller MUST validate target implements an event API before calling listenTo()costlowin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[2] - listenTo · eventemitter2-listen-to-invalid-optionswarningWhenoptions.on or options.off are provided but are not functionsThrows
TypeError('on method must be a function') or TypeError('off method must be a function')Required handlingCaller MUST ensure on/off hooks in options are valid functions when using custom subscription APIcostlowin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[2]
Sources
Every postcondition cites at least one of these. Numbered to match the footnotes above.
- [1]github.com/EventEmitter2/EventEmitter2https://github.com/EventEmitter2/EventEmitter2
- [2]github.com/EventEmitter2/EventEmitter2https://github.com/EventEmitter2/EventEmitter2/blob/master/lib/eventemitter2.js
- [3]developer.mozilla.org/en-US/docshttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all
- [4]github.com/EventEmitter2/EventEmitter2https://github.com/EventEmitter2/EventEmitter2/blob/master/README.md
Need a different package?
Request a profile