Closed mafintosh closed 9 months ago
Doesn't highWaterMark: 0
achieve that?
hwm 0 makes it not read anything ever as you are telling it to never grow the buffer
But if that’s what node makes it mean we can change the flag to that for sure
if that’s what node makes it mean
Yeah, I often use that pattern in tests. Demo:
const { Readable } = require('stream')
async function main () {
const stream = new Readable({
objectMode: true,
highWaterMark: 0,
read (size) {
console.log('read', size)
this.push(new Date())
}
})
for await (const time of stream) {
console.log(time)
await new Promise(resolve => setTimeout(resolve, 5000))
}
}
main()
> node test.js
read 0
read 0
2024-02-17T12:39:31.308Z
2024-02-17T12:39:31.309Z
read 0
2024-02-17T12:39:41.332Z
read 0
2024-02-17T12:39:46.348Z
read 0
2024-02-17T12:39:51.351Z
Except for the first read, apparently.
Ya thats fair, i'll just change the option to that.
Thanks for the assist @vweevers
Allows for disabling read-ahead meaning a _read only happens when someone asks for it and gets a cache-miss.
This is useful for interactive async iterators like