Socket
Book a DemoInstallSign in
Socket

@rainder/co-event-emitter

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rainder/co-event-emitter

co event emitter

latest
Source
npmnpm
Version
0.2.0
Version published
Maintainers
1
Created
Source

CoEventEmitter

API

.on(eventName: String, function: Promise|GeneratorFunction|Thunk): CoEventEmitter

Subscribes for an event. CoEventEmitter allows to subscribe for an event only once. Throws an Error if there is already a listener for an event.

Examples:

//GeneratorFunction implementation
events.on('event-name', function *() {
  return 'result';
});

//Async/Await implementation
events.on('event-name', async function () {
  return 'result';
});

//Thunk implementation
events.on('event-name', (cb) => {
  cb(null, 'result');
});

//Promise implementation
events.on('event-name', new Promise((resolve, reject) => {
  resolve('result');
}));

//Promise v2 implementation
events.on('event-name', () => {
  return Promise.resolve('result');
});

events.emit('event-name', 'hello world')
  .then((result) => console.log(result)); //'hello world'

.off(eventName: String): CoEventEmitter

Removes a subscription for an event. Throws an error if no event listener found.

events.off('event-name');

.has(eventName: String): Boolean

Return true if there is a registered listener for a provided event.

events.has('event-name');

.call(eventName: String, ...args): Promise

Emits an event and returns a promise. Throws an error if no event listener found.

events.call('event-name')
    .then((result) => { /* handle result */ })
    .catch((err) => { /* handle err */ });
}

.emit(eventName: String): Boolean

Emits an event. Returns a boolean value indicating if listener have been found.

events.emit('event-name');

Keywords

co

FAQs

Package last updated on 06 Oct 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts