co-assert-timeout
Advanced tools
Comparing version 0.0.1 to 0.0.2
10
index.js
@@ -19,2 +19,3 @@ var co = require('co') | ||
err.status = 408 | ||
err.exposed = true | ||
err.timeout = timeout | ||
@@ -25,8 +26,5 @@ called = true | ||
fn(function (err) { | ||
if (called) { | ||
if (logger && err) | ||
logger(err) | ||
return | ||
} | ||
fn(function () { | ||
if (called) | ||
return logger && logger.apply(ctx, arguments) | ||
@@ -33,0 +31,0 @@ clearTimeout(id) |
{ | ||
"name": "co-assert-timeout", | ||
"description": "Assert a thunk or generator's timeout co-style", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Jonathan Ong", |
@@ -21,7 +21,7 @@ # Co Assert Timeout [![Build Status](https://travis-ci.org/koajs/co-assert-timeout.png)](https://travis-ci.org/koajs/co-assert-timeout) | ||
not you. | ||
Specifically, you should set a timeout only on the client sending a response: | ||
Specifically, you should set a timeout only on the client sending a request: | ||
```js | ||
app.use(function* (next) { | ||
var buffer = yield assertTimeout(this.request.buffer()) | ||
var buffer = yield assertTimeout(this.request.buffer(), '5 seconds') | ||
}) | ||
@@ -35,5 +35,6 @@ ``` | ||
try { | ||
var buffer = yield assertTimeout(this.request.buffer()) | ||
var buffer = yield assertTimeout(this.request.buffer(), '5 seconds') | ||
} catch (err) { | ||
if (err.status === 408) { | ||
// assertTimeout's errors will have err.status = 408 | ||
// let's make a new error with a custom message | ||
@@ -44,4 +45,7 @@ err = new Error('you took too long to upload') | ||
// rethrow the error | ||
throw err | ||
} | ||
yield next | ||
}) | ||
@@ -52,7 +56,7 @@ ``` | ||
### assertTimeout(fn, timeout, [logger]) | ||
### assertTimeout(fn, timeout, [done]) | ||
- `fn` - a thunk, generator, or generator function | ||
- `timeout` - timeout in milliseconds integer or a string | ||
- `logger` - optional logger if `fn` errors after `timeout` | ||
- `done` - optional callback called only when `fn` finishes executing after the timeout error is thrown | ||
@@ -59,0 +63,0 @@ ## License |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4802
81
51