2019-03-01 20:31:36 +00:00
|
|
|
'use strict';
|
|
|
|
require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const { AsyncLocalStorage } = require('async_hooks');
|
|
|
|
|
|
|
|
const asyncLocalStorage = new AsyncLocalStorage();
|
|
|
|
const asyncLocalStorage2 = new AsyncLocalStorage();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2020-02-24 10:00:59 +00:00
|
|
|
asyncLocalStorage.run(new Map(), () => {
|
|
|
|
asyncLocalStorage2.run(new Map(), () => {
|
2019-03-01 20:31:36 +00:00
|
|
|
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');
|
|
|
|
asyncLocalStorage.exit(() => {
|
|
|
|
assert.strictEqual(asyncLocalStorage.getStore(), undefined);
|
|
|
|
assert.strictEqual(asyncLocalStorage2.getStore().get('hello'), 'foo');
|
|
|
|
});
|
|
|
|
assert.strictEqual(asyncLocalStorage.getStore().get('hello'), 'world');
|
|
|
|
assert.strictEqual(asyncLocalStorage2.getStore().get('hello'), 'foo');
|
|
|
|
}, 200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}, 100);
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2020-02-24 10:00:59 +00:00
|
|
|
asyncLocalStorage.run(new Map(), () => {
|
2019-03-01 20:31:36 +00:00
|
|
|
const store = asyncLocalStorage.getStore();
|
|
|
|
store.set('hello', 'earth');
|
|
|
|
setTimeout(() => {
|
|
|
|
assert.strictEqual(asyncLocalStorage.getStore().get('hello'), 'earth');
|
|
|
|
}, 100);
|
|
|
|
});
|
|
|
|
}, 100);
|