Comparing version 2.4.0 to 2.4.1
{ | ||
"name": "async-es", | ||
"description": "Higher-order functions and common patterns for asynchronous code", | ||
"version": "2.4.0", | ||
"version": "2.4.1", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "author": "Caolan McMahon", |
@@ -46,31 +46,30 @@ import initialParams from './internal/initialParams'; | ||
export default function timeout(asyncFn, milliseconds, info) { | ||
var originalCallback, timer; | ||
var timedOut = false; | ||
var fn = wrapAsync(asyncFn); | ||
function injectedCallback() { | ||
if (!timedOut) { | ||
originalCallback.apply(null, arguments); | ||
clearTimeout(timer); | ||
} | ||
} | ||
return initialParams(function (args, callback) { | ||
var timedOut = false; | ||
var timer; | ||
function timeoutCallback() { | ||
var name = asyncFn.name || 'anonymous'; | ||
var error = new Error('Callback function "' + name + '" timed out.'); | ||
error.code = 'ETIMEDOUT'; | ||
if (info) { | ||
error.info = info; | ||
function timeoutCallback() { | ||
var name = asyncFn.name || 'anonymous'; | ||
var error = new Error('Callback function "' + name + '" timed out.'); | ||
error.code = 'ETIMEDOUT'; | ||
if (info) { | ||
error.info = info; | ||
} | ||
timedOut = true; | ||
callback(error); | ||
} | ||
timedOut = true; | ||
originalCallback(error); | ||
} | ||
var fn = wrapAsync(asyncFn); | ||
args.push(function () { | ||
if (!timedOut) { | ||
callback.apply(null, arguments); | ||
clearTimeout(timer); | ||
} | ||
}); | ||
return initialParams(function (args, origCallback) { | ||
originalCallback = origCallback; | ||
// setup timer and call original function | ||
timer = setTimeout(timeoutCallback, milliseconds); | ||
fn.apply(null, args.concat(injectedCallback)); | ||
fn.apply(null, args); | ||
}); | ||
} |
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
195733
4466