11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst { AsyncLocalStorage } = require('async_hooks');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ci// This is an asynclocalstorage variant of test-timers-clearImmediate.js
71cb0ef41Sopenharmony_ciconst asyncLocalStorage = new AsyncLocalStorage();
81cb0ef41Sopenharmony_ciconst N = 3;
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_cifunction next() {
111cb0ef41Sopenharmony_ci  const fn = common.mustCall(onImmediate);
121cb0ef41Sopenharmony_ci  asyncLocalStorage.run(new Map(), common.mustCall(() => {
131cb0ef41Sopenharmony_ci    const immediate = setImmediate(fn);
141cb0ef41Sopenharmony_ci    const store = asyncLocalStorage.getStore();
151cb0ef41Sopenharmony_ci    store.set('immediate', immediate);
161cb0ef41Sopenharmony_ci  }));
171cb0ef41Sopenharmony_ci}
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_cifunction onImmediate() {
201cb0ef41Sopenharmony_ci  const store = asyncLocalStorage.getStore();
211cb0ef41Sopenharmony_ci  const immediate = store.get('immediate');
221cb0ef41Sopenharmony_ci  assert.strictEqual(immediate.constructor.name, 'Immediate');
231cb0ef41Sopenharmony_ci  clearImmediate(immediate);
241cb0ef41Sopenharmony_ci}
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_cifor (let i = 0; i < N; i++) {
271cb0ef41Sopenharmony_ci  next();
281cb0ef41Sopenharmony_ci}
29