mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
9c702922cd
Adding AsyncLocalStorage class to async_hooks module. This API provide a simple CLS-like set of features. Co-authored-by: Andrey Pechkurov <apechkurov@gmail.com> PR-URL: https://github.com/nodejs/node/pull/26540 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
23 lines
712 B
JavaScript
23 lines
712 B
JavaScript
'use strict';
|
|
require('../common');
|
|
const assert = require('assert');
|
|
const { AsyncLocalStorage } = require('async_hooks');
|
|
|
|
const asyncLocalStorage = new AsyncLocalStorage();
|
|
|
|
setTimeout(() => {
|
|
asyncLocalStorage.run(() => {
|
|
const asyncLocalStorage2 = new AsyncLocalStorage();
|
|
asyncLocalStorage2.run(() => {
|
|
const store = asyncLocalStorage.getStore();
|
|
const store2 = asyncLocalStorage2.getStore();
|
|
store.set('hello', 'world');
|
|
store2.set('hello', 'foo');
|
|
setTimeout(() => {
|
|
assert.strictEqual(asyncLocalStorage.getStore().get('hello'), 'world');
|
|
assert.strictEqual(asyncLocalStorage2.getStore().get('hello'), 'foo');
|
|
}, 200);
|
|
});
|
|
});
|
|
}, 100);
|