mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 02:48:50 +00:00
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com> Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
26 lines
615 B
JavaScript
26 lines
615 B
JavaScript
const { AsyncLocalStorage } = require("async_hooks");
|
|
|
|
const asyncLocalStorage = new AsyncLocalStorage();
|
|
|
|
// Create an async generator
|
|
async function* asyncGenerator() {
|
|
yield 1;
|
|
yield 2;
|
|
yield 3;
|
|
}
|
|
|
|
asyncLocalStorage.run({ test: "async.iterator" }, async () => {
|
|
try {
|
|
for await (const value of asyncGenerator()) {
|
|
if (asyncLocalStorage.getStore()?.test !== "async.iterator") {
|
|
console.error("FAIL: async iterator lost context at value", value);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
process.exit(0);
|
|
} catch (err) {
|
|
console.error("ERROR:", err);
|
|
process.exit(1);
|
|
}
|
|
});
|