File
Blob: src/workerd/api/node/tests/als-gc-test.js
| 1 | // Copyright (c) 2026 Cloudflare, Inc. |
| 2 | // Licensed under the Apache 2.0 license found in the LICENSE file or at: |
| 3 | // https://opensource.org/licenses/Apache-2.0 |
| 4 | |
| 5 | import { AsyncLocalStorage } from 'node:async_hooks'; |
| 6 | |
| 7 | const store = new AsyncLocalStorage(); |
| 8 | |
| 9 | export const test = { |
| 10 | test() { |
| 11 | const outerValue = crypto.randomUUID(); |
| 12 | // eslint-disable-next-line @typescript-eslint/no-unused-expressions |
| 13 | ({ [outerValue]: `value doesn't matter here` }); |
| 14 | store.run(outerValue, () => { |
| 15 | for (let i = 0; i < 1_000; i++) { |
| 16 | const storeValue = store.getStore(); |
| 17 | if (!storeValue) { |
| 18 | throw new Error(`Failed on attempt ${i}.`); |
| 19 | } |
| 20 | for (let j = 0; j < 1_000; j++) { |
| 21 | (() => Math.random())(); |
| 22 | } |
| 23 | } |
| 24 | }); |
| 25 | }, |
| 26 | }; |