1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const { AsyncLocalStorage } = require('async_hooks'); 5 6// This is an asynclocalstorage variant of test-timers-clearImmediate.js 7const asyncLocalStorage = new AsyncLocalStorage(); 8const N = 3; 9 10function next() { 11 const fn = common.mustCall(onImmediate); 12 asyncLocalStorage.run(new Map(), common.mustCall(() => { 13 const immediate = setImmediate(fn); 14 const store = asyncLocalStorage.getStore(); 15 store.set('immediate', immediate); 16 })); 17} 18 19function onImmediate() { 20 const store = asyncLocalStorage.getStore(); 21 const immediate = store.get('immediate'); 22 assert.strictEqual(immediate.constructor.name, 'Immediate'); 23 clearImmediate(immediate); 24} 25 26for (let i = 0; i < N; i++) { 27 next(); 28} 29