on-finished
Advanced tools
Comparing version 2.4.0 to 2.4.1
@@ -0,1 +1,6 @@ | ||
2.4.1 / 2022-02-22 | ||
================== | ||
* Fix error on early async hooks implementations | ||
2.4.0 / 2022-02-21 | ||
@@ -2,0 +7,0 @@ ================== |
18
index.js
@@ -209,3 +209,2 @@ /*! | ||
} catch (e) { | ||
/* istanbul ignore next */ | ||
return {} | ||
@@ -216,3 +215,4 @@ } | ||
/** | ||
* Wrap function with async resource | ||
* Wrap function with async resource, if possible. | ||
* AsyncResource.bind static method backported. | ||
* @private | ||
@@ -222,10 +222,16 @@ */ | ||
function wrap (fn) { | ||
if (!asyncHooks.AsyncResource) { | ||
/* istanbul ignore next */ | ||
var res | ||
// create anonymous resource | ||
if (asyncHooks.AsyncResource) { | ||
res = new asyncHooks.AsyncResource(fn.name || 'bound-anonymous-fn') | ||
} | ||
// incompatible node.js | ||
if (!res || !res.runInAsyncScope) { | ||
return fn | ||
} | ||
// AsyncResource.bind static method backported | ||
var res = new asyncHooks.AsyncResource(fn.name || 'bound-anonymous-fn') | ||
// return bound function | ||
return res.runInAsyncScope.bind(res, fn, null) | ||
} |
{ | ||
"name": "on-finished", | ||
"description": "Execute a callback when a request closes, finishes, or errors", | ||
"version": "2.4.0", | ||
"version": "2.4.1", | ||
"contributors": [ | ||
@@ -6,0 +6,0 @@ "Douglas Christopher Wilson <doug@somethingdoug.com>", |
13679
186