npm.io
1.1.6 • Published 8 years ago

ko-timeout

Licence
MIT
Version
1.1.6
Deps
4
Vulns
1
Weekly
0
Stars
4

ko-timeout

deprecated please use https://github.com/sindresorhus/delay

Build Status

usage

timeout(gen, ms)

gen - a genarator function

ms - millisecond. can use '3s' or '200ms', which https://www.npmjs.com/package/ms support

if timeout, err.name will be CoTimeoutError

example

should timeout
try {
  yield timeout(function * () {
    yield sleep(50)
  }, 20)
} catch (e) {
  e.message.should.eql('timeout: exceed 20ms')
}
should get return value
var value = yield timeout(function * () {
  yield sleep(10)
  return 30;
}, 20)

value.should.eql(30)

license

MIT

Keywords