Simple wait/notify promise with optional max wait time
npm install signal-promise
const Signal = require('signal-promise')
const input = new Signal()
process.stdin.on('data', function () {
input.notify()
})
while (await input.wait()) {
console.log('someone typed!')
}
Make a new signal
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.
Notify everyone waiting. If you pass an error the wait promise will reject with that error.
MIT