by molsson · 2y ago · 0 comments
...is a bit brutal but works. Draining the stream before exiting also kind of works but there are cases where drain will just permanently block.
async function drain(stream) { return new Promise((resolve) => stream.on('drain', resolve)) }
This program will run forever, since we never write to stdout, stdout never "drains":
setInterval(() => console.error("stderr: ", new Date().toISOString()), 5_000)
process.stdout.once("drain", () => {
console.error("stderr: stdout.once.drain, exit")
process.exit(0)
})