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>
29 lines
794 B
JavaScript
29 lines
794 B
JavaScript
const { AsyncLocalStorage } = require("async_hooks");
|
|
const { Writable } = require("stream");
|
|
|
|
const asyncLocalStorage = new AsyncLocalStorage();
|
|
let failed = false;
|
|
|
|
asyncLocalStorage.run({ test: "stream.Writable" }, () => {
|
|
const writable = new Writable({
|
|
write(chunk, encoding, callback) {
|
|
if (asyncLocalStorage.getStore()?.test !== "stream.Writable") {
|
|
console.error("FAIL: Writable stream write method lost context");
|
|
failed = true;
|
|
}
|
|
callback();
|
|
},
|
|
});
|
|
|
|
writable.on("finish", () => {
|
|
if (asyncLocalStorage.getStore()?.test !== "stream.Writable") {
|
|
console.error("FAIL: Writable stream finish event lost context");
|
|
failed = true;
|
|
}
|
|
process.exit(failed ? 1 : 0);
|
|
});
|
|
|
|
writable.write("test");
|
|
writable.end();
|
|
});
|