1'use strict'; 2require('../common'); 3const assert = require('assert'); 4const { AsyncLocalStorage } = require('async_hooks'); 5 6const asyncLocalStorage = new AsyncLocalStorage(); 7 8asyncLocalStorage.run(new Map(), () => { 9 asyncLocalStorage.getStore().set('foo', 'bar'); 10 process.nextTick(() => { 11 assert.strictEqual(asyncLocalStorage.getStore().get('foo'), 'bar'); 12 process.nextTick(() => { 13 assert.strictEqual(asyncLocalStorage.getStore(), undefined); 14 }); 15 16 asyncLocalStorage.disable(); 17 assert.strictEqual(asyncLocalStorage.getStore(), undefined); 18 19 // Calls to exit() should not mess with enabled status 20 asyncLocalStorage.exit(() => { 21 assert.strictEqual(asyncLocalStorage.getStore(), undefined); 22 }); 23 assert.strictEqual(asyncLocalStorage.getStore(), undefined); 24 25 process.nextTick(() => { 26 assert.strictEqual(asyncLocalStorage.getStore(), undefined); 27 asyncLocalStorage.run(new Map().set('bar', 'foo'), () => { 28 assert.strictEqual(asyncLocalStorage.getStore().get('bar'), 'foo'); 29 }); 30 }); 31 }); 32}); 33