https://github.com/yejiayu/wait
wait event
https://github.com/yejiayu/wait
event nodejs wait
Last synced: 3 months ago
JSON representation
wait event
- Host: GitHub
- URL: https://github.com/yejiayu/wait
- Owner: yejiayu
- Created: 2017-03-23T08:05:17.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-30T08:39:50.000Z (almost 9 years ago)
- Last Synced: 2025-02-19T06:35:02.568Z (about 1 year ago)
- Topics: event, nodejs, wait
- Language: JavaScript
- Homepage:
- Size: 4 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# wait-event
> wait event
## Install
```js
$ npm i wait-event --save
```
## Usage
```js
const wait = require('wait-event');
const { EventEmitter } = require('events');
const event = new EventEmitter()
setTimeout(() => {
event.emit('ready', 'ready')
}, 4000)
setTimeout(() => {
event.emit('timeout')
}, 6000)
async () => {
const result = await wait(event, 'ready')
try {
await wait(event, 'timeout', 5000)
} catch (e) {
console.log(e.name); // TimeoutError
}
// always.....
await wait(event, 'always-wait')
}
```