mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
Adds support for using scope = storage.withScope(data) to do the equivalent of a storage.run(data, fn) with using syntax. This enables avoiding unnecessary closures. PR-URL: https://github.com/nodejs/node/pull/61674 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Bryan English <bryan@bryanenglish.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
32 lines
487 B
JavaScript
32 lines
487 B
JavaScript
'use strict';
|
|
|
|
const {
|
|
SymbolDispose,
|
|
} = primordials;
|
|
|
|
class RunScope {
|
|
#storage;
|
|
#previousStore;
|
|
#disposed = false;
|
|
|
|
constructor(storage, store) {
|
|
this.#storage = storage;
|
|
this.#previousStore = storage.getStore();
|
|
storage.enterWith(store);
|
|
}
|
|
|
|
dispose() {
|
|
if (this.#disposed) {
|
|
return;
|
|
}
|
|
this.#disposed = true;
|
|
this.#storage.enterWith(this.#previousStore);
|
|
}
|
|
|
|
[SymbolDispose]() {
|
|
this.dispose();
|
|
}
|
|
}
|
|
|
|
module.exports = RunScope;
|