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 |
|
5 | This is a sub-package of [web3.js][repo].
|
6 |
|
7 | This is the PromiEvent package used to return a EventEmitter mixed with a Promise to allow multiple final states as well as chaining.
|
8 |
|
9 | Please read the [documentation][docs] for more.
|
10 |
|
11 | ## Installation
|
12 |
|
13 | ### Node.js
|
14 |
|
15 | ```bash
|
16 | npm install web3-core-promievent
|
17 | ```
|
18 |
|
19 | ## Usage
|
20 |
|
21 | ```js
|
22 | const Web3PromiEvent = require('web3-core-promievent');
|
23 |
|
24 | const 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
|
36 | myFunc()
|
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
|