HardAtWork
04/23/2023, 12:51 PMsathoro
04/23/2023, 12:52 PMsathoro
04/23/2023, 12:52 PMsathoro
04/23/2023, 12:52 PMHardAtWork
04/23/2023, 12:52 PMHardAtWork
04/23/2023, 12:53 PMsathoro
04/23/2023, 12:53 PMHardAtWork
04/23/2023, 12:54 PM--experimental-local
after all. What OS are you on?sathoro
04/23/2023, 12:55 PMfoo
and then access it in another filesathoro
04/23/2023, 12:55 PMsathoro
04/23/2023, 12:56 PMHardAtWork
04/23/2023, 12:57 PMworkerd
was, until recently Unix(more like Ubuntu) only, and while a PR to add support to Windows was recently merged, there are probably still some issues to be ironed out...sathoro
04/23/2023, 12:58 PMrun
to access the storagesathoro
04/23/2023, 12:59 PMsathoro
04/23/2023, 1:00 PMsathoro
04/23/2023, 1:01 PMasyncLocalStorage
instance?HardAtWork
04/23/2023, 1:03 PMsathoro
04/23/2023, 1:03 PMHardAtWork
04/23/2023, 1:04 PMHardAtWork
04/23/2023, 1:05 PMsathoro
04/23/2023, 1:05 PMsathoro
04/23/2023, 1:05 PMHardAtWork
04/23/2023, 1:05 PMsathoro
04/23/2023, 1:07 PMconst asyncLocalStorage = new AsyncLocalStorage();
await asyncLocalStorage.getStore(); // undefined
from an inner function (like a route), this just returns undefined. so I think you do need to pass around the original asyncLocalStorage
instancesathoro
04/23/2023, 1:07 PMsathoro
04/23/2023, 1:10 PMjs
const asyncLocalStorage = new AsyncLocalStorage();
export const getLocalStorage = () => asyncLocalStorage.getStore();
let idSeq = 0;
export default {
async fetch(request, env, context) {
return asyncLocalStorage.run(idSeq++, async () => {
...
second file:
js
import { getLocalStorage } from "../index";
await getLocalStorage();
sathoro
04/23/2023, 1:12 PMMurder Chicken
04/23/2023, 1:30 PMkian
04/23/2023, 1:40 PMkian
04/23/2023, 1:40 PM