mafintosh / signal-promise

Simple wait/notify promise with optional max wait time

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

signal-promise

Simple wait/notify promise with optional max wait time

npm install signal-promise

Usage

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

About

Simple wait/notify promise with optional max wait time

License:MIT License


Languages

Language:JavaScript 100.0%