1'use strict'; 2require('../common'); 3const assert = require('assert'); 4const { AsyncLocalStorage } = require('async_hooks'); 5 6async function foo() {} 7 8const asyncLocalStorage = new AsyncLocalStorage(); 9 10async function testOut() { 11 await foo(); 12 assert.strictEqual(asyncLocalStorage.getStore(), undefined); 13} 14 15async function testAwait() { 16 await foo(); 17 assert.notStrictEqual(asyncLocalStorage.getStore(), undefined); 18 assert.strictEqual(asyncLocalStorage.getStore().get('key'), 'value'); 19 await asyncLocalStorage.exit(testOut); 20} 21 22asyncLocalStorage.run(new Map(), () => { 23 const store = asyncLocalStorage.getStore(); 24 store.set('key', 'value'); 25 testAwait(); // should not reject 26}); 27assert.strictEqual(asyncLocalStorage.getStore(), undefined); 28