chore: import upstream snapshot with attribution
Deploy (to testing) and Test Playground Preview Worker / Deploy Playground Preview Worker (testing) (push) Has been skipped
Deploy Workers Shared Staging / Deploy Workers Shared Staging (push) Failing after 0s
Prerelease / build (push) Has been skipped
Handle Changesets / Handle Changesets (push) Has been cancelled
Semgrep OSS scan / semgrep-oss (push) Has been cancelled
Deploy (to testing) and Test Playground Preview Worker / Deploy Playground Preview Worker (testing) (push) Has been skipped
Deploy Workers Shared Staging / Deploy Workers Shared Staging (push) Failing after 0s
Prerelease / build (push) Has been skipped
Handle Changesets / Handle Changesets (push) Has been cancelled
Semgrep OSS scan / semgrep-oss (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { AsyncLocalStorage } from "node:async_hooks";
|
||||
|
||||
const asyncLocalStorage = new AsyncLocalStorage<number>();
|
||||
|
||||
export default {
|
||||
async fetch(req: Request, env: unknown, ctx: ExecutionContext) {
|
||||
if (new URL(req.url).pathname !== "/") {
|
||||
return new Response("No Found", { status: 404 });
|
||||
}
|
||||
|
||||
const results = await Promise.all([
|
||||
asyncLocalStorage.run(1, async () => getValue()),
|
||||
asyncLocalStorage.run(2, async () => getValue()),
|
||||
asyncLocalStorage.run(3, async () => getValue()),
|
||||
]);
|
||||
|
||||
return new Response(`Working ${JSON.stringify(results)}`);
|
||||
},
|
||||
};
|
||||
|
||||
async function getValue() {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
return asyncLocalStorage.getStore();
|
||||
}
|
||||
Reference in New Issue
Block a user