signal-promise
Simple wait/notify promise with optional max wait time
Last updated 5 years ago by mafintosh .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install signal-promise 
SYNC missed versions from official npm registry.

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()

while (await input.wait()) {
  console.log('someone typed!')
}

process.stdin.on('stdin', function () {
  input.notify()
})

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

Current Tags

  • 1.0.3                                ...           latest (5 years ago)

5 Versions

  • 1.0.3                                ...           5 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
  • 0.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Total 1
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE