lib: add AsyncLocalStorage.bind() and .snapshot()

PR-URL: https://github.com/nodejs/node/pull/46387
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
This commit is contained in:
flakey5 2023-01-27 17:12:00 -08:00 committed by James M Snell
parent 225c578c77
commit 9a82938b82
4 changed files with 91 additions and 0 deletions

View file

@ -287,6 +287,14 @@ class AsyncLocalStorage {
this.enabled = false;
}
static bind(fn) {
return AsyncResource.bind(fn);
}
static snapshot() {
return AsyncLocalStorage.bind((cb, ...args) => cb(...args));
}
disable() {
if (this.enabled) {
this.enabled = false;