UNPKG

1.48 kBMarkdownView Raw
1# web3-core-promievent
2
3[![NPM Package][npm-image]][npm-url] [![Dependency Status][deps-image]][deps-url] [![Dev Dependency Status][deps-dev-image]][deps-dev-url]
4
5This is a sub-package of [web3.js][repo].
6
7This is the PromiEvent package used to return a EventEmitter mixed with a Promise to allow multiple final states as well as chaining.
8
9Please read the [documentation][docs] for more.
10
11## Installation
12
13### Node.js
14
15```bash
16npm install web3-core-promievent
17```
18
19## Usage
20
21```js
22const Web3PromiEvent = require('web3-core-promievent');
23
24const myFunc = function(){
25 const promiEvent = Web3PromiEvent();
26
27 setTimeout(function() {
28 promiEvent.eventEmitter.emit('done', 'Hello!');
29 promiEvent.resolve('Hello!');
30 }, 10);
31
32 return promiEvent.eventEmitter;
33};
34
35// and run it
36myFunc()
37.on('done', console.log)
38.then(console.log);
39```
40
41[docs]: http://web3js.readthedocs.io/en/1.0/
42[repo]: https://github.com/ethereum/web3.js
43[npm-image]: https://img.shields.io/npm/v/web3-core-promievent.svg
44[npm-url]: https://npmjs.org/package/web3-core-promievent
45[deps-image]: https://david-dm.org/ethereum/web3.js/1.x/status.svg?path=packages/web3-core-promievent
46[deps-url]: https://david-dm.org/ethereum/web3.js/1.x?path=packages/web3-core-promievent
47[deps-dev-image]: https://david-dm.org/ethereum/web3.js/1.x/dev-status.svg?path=packages/web3-core-promievent
48[deps-dev-url]: https://david-dm.org/ethereum/web3.js/1.x?type=dev&path=packages/web3-core-promievent