diff options
author | 2023-07-19 17:20:00 -0700 | |
---|---|---|
committer | 2023-07-19 17:20:00 -0700 | |
commit | 9b6dc49575df5fb953918c284505f24741138130 (patch) | |
tree | 3a052876fa8c6524e0c8d18479aabe38e2d5a52a /test/js/node/async_hooks/async_hooks.node.test.ts | |
parent | 723e9d1ea7c7fdb424ecedd0fb023524366322c4 (diff) | |
download | bun-9b6dc49575df5fb953918c284505f24741138130.tar.gz bun-9b6dc49575df5fb953918c284505f24741138130.tar.zst bun-9b6dc49575df5fb953918c284505f24741138130.zip |
Implement `AsyncLocalStorage` (#3089)
* work to get async local storage working.
* a
* a
* everything but queueMicrotask
* sdfghj
* .
* finish
* tests
* test
* ok
* done
* im so stupid
* Upgrade WebKit
* refactor
* refactor
* changes requested
* oops
* cool
* fix runInAsyncScope
Diffstat (limited to 'test/js/node/async_hooks/async_hooks.node.test.ts')
-rw-r--r-- | test/js/node/async_hooks/async_hooks.node.test.ts | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/js/node/async_hooks/async_hooks.node.test.ts b/test/js/node/async_hooks/async_hooks.node.test.ts new file mode 100644 index 000000000..107c58a8c --- /dev/null +++ b/test/js/node/async_hooks/async_hooks.node.test.ts @@ -0,0 +1,34 @@ +import { AsyncLocalStorage } from "async_hooks"; +import assert from "assert"; + +test("node async_hooks.AsyncLocalStorage enable disable", async () => { + const asyncLocalStorage = new AsyncLocalStorage(); + + asyncLocalStorage.run(new Map(), () => { + asyncLocalStorage.getStore().set("foo", "bar"); + process.nextTick(() => { + assert.strictEqual(asyncLocalStorage.getStore().get("foo"), "bar"); + process.nextTick(() => { + assert.strictEqual(asyncLocalStorage.getStore(), undefined); + }); + + asyncLocalStorage.disable(); + assert.strictEqual(asyncLocalStorage.getStore(), undefined); + + // Calls to exit() should not mess with enabled status + asyncLocalStorage.exit(() => { + assert.strictEqual(asyncLocalStorage.getStore(), undefined); + }); + assert.strictEqual(asyncLocalStorage.getStore(), undefined); + + process.nextTick(() => { + assert.strictEqual(asyncLocalStorage.getStore(), undefined); + asyncLocalStorage.run(new Map().set("bar", "foo"), () => { + assert.strictEqual(asyncLocalStorage.getStore().get("bar"), "foo"); + + done(); + }); + }); + }); + }); +}); |