aboutsummaryrefslogtreecommitdiff
path: root/src/js/node/async_hooks.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/js/node/async_hooks.ts')
-rw-r--r--src/js/node/async_hooks.ts24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/js/node/async_hooks.ts b/src/js/node/async_hooks.ts
index ef77b79f7..8fc9b772f 100644
--- a/src/js/node/async_hooks.ts
+++ b/src/js/node/async_hooks.ts
@@ -200,6 +200,30 @@ class AsyncResource {
set(prev);
}
}
+
+ bind(fn, thisArg) {
+ if (typeof fn !== "function") {
+ const invalidArgType = new TypeError('The "fn" argument must be of type function. Received type ' + typeof fn);
+ invalidArgType.code = "ERR_INVALID_ARG_TYPE";
+ throw invalidArgType;
+ }
+
+ let bound;
+ if (thisArg === undefined) {
+ const resource = this;
+ bound = function (...args) {
+ return resource.runInAsyncScope(resource, undefined, args as any);
+ };
+ } else {
+ bound = this.runInAsyncScope.bind(this, fn, thisArg);
+ }
+ }
+
+ static bind(fn, type, thisArg) {
+ type = type || fn.name;
+ const boundFn = AsyncResource.prototype["bind"];
+ return boundFn.call(new AsyncResource(type || "bound-anonymous-fn", undefined), fn, thisArg);
+ }
}
// The rest of async_hooks is not implemented and is stubbed with no-ops and warnings.