jon
jon3mo ago

AsyncLocalStorage without `node:async_hooks`

I'm trying to remove dependencies on node: in a Deno project. I just came across https://github.com/nodejs/node/pull/48528 and I'm wondering if it could unlock AsyncLocalStorage without a dependency on node:async_hooks for Deno. I am having a bit of a hard time following the various PRs/Github issues, but I also found some fairly recent work that seems related: https://github.com/denoland/deno/pull/25140 https://github.com/denoland/deno/pull/24402
GitHub
lib: rewrite AsyncLocalStorage without async_hooks by Qard · Pull R...
I'm working on rewriting AsyncLocalStorage to use v8::SetContinuationPreservedEmbedderData(...) in a similar model to Cloudflare and in anticipation of the upcoming AsyncContext proposal. T...
GitHub
fix: reland async context by devsnek · Pull Request #25140 · denola...
This reverts commit 71ca61e. Now uses a shared implementation from deno_core.
GitHub
feat: async context by devsnek · Pull Request #24402 · denoland/deno
We are switching to ContinuationPreservedEmbedderData. This allows adding async context tracking to the various async operations that deno provides. Fixes: #7010 Fixes: #22886 Fixes: #24368
5 Replies
bartlomieju
bartlomieju3mo ago
Deno's ALS doesn't use async_hooks, but it's still exported from that module
jon
jonOP2mo ago
I see. Given that, is there another way to import Deno's AsyncLocalStorage other than through node:async_hooks? Particularly, I am interested in avoiding deno_emit errors related to using node:
bartlomieju
bartlomieju2mo ago
Not really no, it's the only way
jon
jonOP2mo ago
OK, I think that'll be a blocker for my use case... as a workaround, if it is possible already to host a private instance of JSR, that could also work.
bartlomieju
bartlomieju2mo ago
Yeah you can host private instance But then you will have to override all calls to jsr: in Deno - ie all jsr: dependencies would be pulled from your instance, you can route some of them to public one and others to your private one (like .npmrc file does for npm) You'd need to set JSR_URL env var to override the URL used