From 6803c25083c166ee6bb83051b6876e764caedc09 Mon Sep 17 00:00:00 2001 From: Harshitha KP Date: Mon, 16 Mar 2020 10:59:39 -0400 Subject: [PATCH] test: als variant of test-timers-clearImmediate Refs: https://github.com/nodejs/node/issues/31978 --- .../test-timers-clearImmediate-als.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 test/parallel/test-timers-clearImmediate-als.js diff --git a/test/parallel/test-timers-clearImmediate-als.js b/test/parallel/test-timers-clearImmediate-als.js new file mode 100644 index 00000000000000..1e37fc5c5b759f --- /dev/null +++ b/test/parallel/test-timers-clearImmediate-als.js @@ -0,0 +1,24 @@ +'use strict'; +const common = require('../common'); +const { AsyncLocalStorage } = require('async_hooks'); +const asyncLocalStorage = new AsyncLocalStorage(); +const N = 3; + +function next() { + const fn = common.mustCall(onImmediate); + asyncLocalStorage.run(new Map(), common.mustCall(() => { + const immediate = setImmediate(fn); + const store = asyncLocalStorage.getStore(); + store.set('immediate', immediate); + })); +} + +function onImmediate() { + const store = asyncLocalStorage.getStore(); + const immediate = store.get('immediate'); + clearImmediate(immediate); +} + +for (let i = 0; i < N; i++) { + next(); +}