File tree 1 file changed +28
-0
lines changed
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments