@promises/from-event
v0.5.0
Published
From Event is package from Promises library
Downloads
20
Maintainers
Readme
@promises/from-event
From Event is package from Promises library
Use
Module
$ npm install --save @promises/from-event
import {
default as fromEvent
} from '@promises/from-event';
Browser
<script src="https://unpkg.com/@promises/from-event/bundle.umd.min.js"></script>
let {
fromEvent
} = P;
Examples
let emitter: EventEmitter = new EventEmitter();
Promise.race([
fromEvent(emitter, 'foo'),
fromEvent(emitter, 'error', {reject: true})
]).catch((error: string) => {
console.log(error); // error => 'some error'
});
emitter.emit('error', 'some error');
Wrapper
Module
$ npm install --save @promises/from-event
import Promises from '@promises/core';
import '@promises/from-event/add';
Or
import Promises from '@promises/from-event/add';
Browser
<script src="https://unpkg.com/@promises/core/bundle.umd.min.js"></script>
<script src="https://unpkg.com/@promises/from-event/add/bundle.umd.min.js"></script>
let {
Promises
} = P;
Examples
let emitter: EventEmitter = new EventEmitter()
Promises.fromEvent(emitter, 'foo').then((data: string) => {
console.log(data); // data => 'bar'
});
emitter.emit('foo', 'bar');
Compatibility
These modules are written in typescript and available in ES5 and ES6 standard, the requirements are a global Promise (native or polyfill).
License
Copyright © 2017 Yisrael Eliav, Licensed under the MIT license.