ko-timeout

1.1.6 • Public • Published

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

Package Sidebar

Install

npm i ko-timeout

Weekly Downloads

1

Version

1.1.6

License

MIT

Last publish

Collaborators

  • alsotang