This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

@kajigoku/event-emitter

3.0.1 • Public • Published

Event emitter

High performance event emitter, particularly useful for getChildContext.

Usage

import { EventEmitter } from '@kajigoku/event-emitter'

// Create a new instance
eventEmitter = new EventEmitter()

// Add a callback that will be invoked every time an event is emitted.
eventEmitter.on(callback)

// Add a callback that will be invoked the next time the event is fired, then it will be removed.
eventEmitter.once(callback)
// If a callback is not provided, a promise is returned
const newPromise = eventEmitter.once()
// A parameter can be provided, the number of millisecond will be used as timeout timer.
const timeoutPromise = eventEmitter.once(420)

// Remove a listener
eventEmitter.off(callback)
// Remove all listeners
eventEmitter.off()

// Emit an event, data may be attached to the event by passing it as parameter
eventEmitter.emit(data)
// More than one parameter can be passed to emit, fastest operation is achieved with 0-3 parameters.
eventEmitter.emit(data, moreData, evenMoreData)

// Return the number of listeners
eventEmitter.listenerCount()

Package Sidebar

Install

npm i @kajigoku/event-emitter

Weekly Downloads

2

Version

3.0.1

License

NCSA

Unpacked Size

7.08 kB

Total Files

4

Last publish

Collaborators

  • coachonko