Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mafintosh/signal-promise
Simple wait/notify promise with optional max wait time
https://github.com/mafintosh/signal-promise
Last synced: 12 days ago
JSON representation
Simple wait/notify promise with optional max wait time
- Host: GitHub
- URL: https://github.com/mafintosh/signal-promise
- Owner: mafintosh
- License: mit
- Created: 2020-03-03T19:28:01.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-03-04T06:48:45.000Z (over 4 years ago)
- Last Synced: 2024-10-22T15:58:05.636Z (22 days ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 43
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# signal-promise
Simple wait/notify promise with optional max wait time
```
npm install signal-promise
```## Usage
``` js
const Signal = require('signal-promise')const input = new Signal()
process.stdin.on('data', function () {
input.notify()
})while (await input.wait()) {
console.log('someone typed!')
}
```## API
#### `s = new Signal()`
Make a new signal
#### `await s.wait([maxWaitTime])`
Wait for someone to call notify. If you specify `maxWaitTime`
the promise will resolve after `maxWaitTime` ms if no notify call has happened.As a convenience the promise resolves to `true` so it's easy to use it as a condition.
#### `s.notify([error])`
Notify everyone waiting. If you pass an error the wait promise
will reject with that error.## License
MIT