Skip to content

Commit 1905b9e

Browse files
HarshithaKPaddaleax
authored andcommitted
test: als variant of test-timers-clearImmediate
Refs: #31978 PR-URL: #32303 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 72983d2 commit 1905b9e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const { AsyncLocalStorage } = require('async_hooks');
5+
6+
// This is an asynclocalstorage variant of test-timers-clearImmediate.js
7+
const asyncLocalStorage = new AsyncLocalStorage();
8+
const N = 3;
9+
10+
function 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+
19+
function onImmediate() {
20+
const store = asyncLocalStorage.getStore();
21+
const immediate = store.get('immediate');
22+
assert.strictEqual(immediate.constructor.name, 'Immediate');
23+
clearImmediate(immediate);
24+
}
25+
26+
for (let i = 0; i < N; i++) {
27+
next();
28+
}

0 commit comments

Comments
 (0)