While experimenting with readable.read()
and readable.once('redable')
I stumbled upon a peculiar problem. Seems like one of the abote kills my node.js process without any error.
I would expect that the following code will throw an error or will hang indefinitely
const { createReadStream } = require('fs');
process.on('unhandledRejection', error => {
console.log(error)
});
process.on('error', e => {
console.log('error', e)
});
process.on('exit', e => {
console.log('exit', e)
});
(async () => {
// test.txt is an empty file
const stream = createReadStream('test.txt', { encoding: 'utf-8' })
const waitForReadable = () => new Promise(r => stream.once('readable', r))
for (let i = 0; i < 1000; i += 1) {
console.log(i)
stream.read()
await waitForReadable()
}
})()
But instead, it outputs:
0
1
exit 0