mirror of
https://github.com/nodejs/node.git
synced 2025-04-29 06:19:07 +00:00

PR-URL: https://github.com/nodejs/node/pull/31950 Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
33 lines
1.0 KiB
JavaScript
33 lines
1.0 KiB
JavaScript
'use strict';
|
|
require('../common');
|
|
const assert = require('assert');
|
|
const { AsyncLocalStorage } = require('async_hooks');
|
|
|
|
const asyncLocalStorage = new AsyncLocalStorage();
|
|
|
|
asyncLocalStorage.run(new Map(), () => {
|
|
asyncLocalStorage.getStore().set('foo', 'bar');
|
|
process.nextTick(() => {
|
|
assert.strictEqual(asyncLocalStorage.getStore().get('foo'), 'bar');
|
|
process.nextTick(() => {
|
|
assert.strictEqual(asyncLocalStorage.getStore(), undefined);
|
|
});
|
|
|
|
asyncLocalStorage.disable();
|
|
assert.strictEqual(asyncLocalStorage.getStore(), undefined);
|
|
|
|
// Calls to exit() should not mess with enabled status
|
|
asyncLocalStorage.exit(() => {
|
|
assert.strictEqual(asyncLocalStorage.getStore(), undefined);
|
|
});
|
|
assert.strictEqual(asyncLocalStorage.getStore(), undefined);
|
|
|
|
process.nextTick(() => {
|
|
assert.strictEqual(asyncLocalStorage.getStore(), undefined);
|
|
asyncLocalStorage.run(new Map(), () => {
|
|
assert.notStrictEqual(asyncLocalStorage.getStore(), undefined);
|
|
});
|
|
});
|
|
});
|
|
});
|