Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alsotang/ko-timeout
https://github.com/alsotang/ko-timeout
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/alsotang/ko-timeout
- Owner: alsotang
- License: mit
- Created: 2015-11-14T19:33:41.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-10-19T03:33:11.000Z (about 7 years ago)
- Last Synced: 2024-09-29T05:44:49.230Z (3 months ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ko-timeout
**deprecated please use https://github.com/sindresorhus/delay**
[![Build Status](https://travis-ci.org/alsotang/ko-timeout.svg?branch=master)](https://travis-ci.org/alsotang/ko-timeout)
## usage
```js
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
```js
try {
yield timeout(function * () {
yield sleep(50)
}, 20)
} catch (e) {
e.name.should.eql('CoTimeoutError')
e.message.should.eql('timeout: exceed 20ms')
}
```### should get return value
```js
var value = yield timeout(function * () {
yield sleep(10)
return 30;
}, 20)value.should.eql(30)
```## license
MIT