Skip to content

Asynchronous (using ES2015 Promises) event emitter supporting regex listeners

License

Notifications You must be signed in to change notification settings

sealcode/pattern-emitter-promise

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pattern-emitter-promise

Build Status npm version

Asynchronous (using ES2015 Promises) event emitter supporting regex listeners

Installation

Just do:

npm install pattern-emitter-promise

and you are ready.

This lib has no external dependencies. Library should be used in environment with Promise global constructor. If there is no such constructor (node 0.10 and earlier or some older browsers), Promise library must be set before first instantiation using setPromiseLibrary static method.

Usage

In your code:

import { EventEmitter } from 'event-emitter-promise';

let ee = EventEmitter();

ee.on('fooBar', () => {
    return Promise.resolve('fooBar1');
});

ee.on(/^foo/, (bar) => {
    return Promise.resolve('foo' + bar + '2');
});

ee.on('fooBar', () => {
    return 'fooBar3'; //we support sync return too
});

ee.emit('fooBar', 'Bar').then((results) => {
    results; // ['fooBar1', 'fooBar2', 'fooBar3']
});

For more usage examples see tests and read docs in the code.

License

MIT

About

Asynchronous (using ES2015 Promises) event emitter supporting regex listeners

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%