1'use strict'; 2require('../common'); 3const assert = require('assert'); 4const { AsyncLocalStorage } = require('async_hooks'); 5 6// case 2 using *AndReturn calls (dual behaviors) 7const asyncLocalStorage = new AsyncLocalStorage(); 8 9let i = 0; 10process.setUncaughtExceptionCaptureCallback((err) => { 11 ++i; 12 assert.strictEqual(err.message, 'err2'); 13 assert.strictEqual(asyncLocalStorage.getStore().get('hello'), 'node'); 14}); 15 16try { 17 asyncLocalStorage.run(new Map(), () => { 18 const store = asyncLocalStorage.getStore(); 19 store.set('hello', 'node'); 20 setTimeout(() => { 21 process.nextTick(() => { 22 assert.strictEqual(i, 1); 23 }); 24 throw new Error('err2'); 25 }, 0); 26 throw new Error('err1'); 27 }); 28} catch (e) { 29 assert.strictEqual(e.message, 'err1'); 30 assert.strictEqual(asyncLocalStorage.getStore(), undefined); 31} 32