top | item 41829850 (no title) ecedeno | 1 year ago > node -e "process.stdout.write('@'.repeat(128 * 1024)); process.stdout.write(''); process.exit(0);" | wc -cThat's missing the part where it waits for the last write to flush before exiting. discuss order hn newest 3np|1 year ago You might think that would be it? $ node -e "process.stdout.write('@'.repeat(128 * 1024)); process.stdout.write(''); setTimeout(()=>{ process.exit(0); }, 0);" | wc -c 131072 Sure. But not so fast! You're still just racing and have no guarantees. Increase the pressure and it snaps back: $ node -e "process.stdout.write('@'.repeat(1280 * 1024)); process.stdout.write(''); setTimeout(()=>{ process.exit(0); }, 0);" | wc -c 65536 Meanwhile: $ node -e "const { Stream } = require('stream'); s = process.stdout; s.write('@'.repeat(1280 * 1024)); Stream.finished(s, () => { process.exit(0); })" | wc -c 1310720 unknown|1 year ago [deleted] Thorrez|1 year ago You're not passing anything into the 2nd parameter of stdout.write()
3np|1 year ago You might think that would be it? $ node -e "process.stdout.write('@'.repeat(128 * 1024)); process.stdout.write(''); setTimeout(()=>{ process.exit(0); }, 0);" | wc -c 131072 Sure. But not so fast! You're still just racing and have no guarantees. Increase the pressure and it snaps back: $ node -e "process.stdout.write('@'.repeat(1280 * 1024)); process.stdout.write(''); setTimeout(()=>{ process.exit(0); }, 0);" | wc -c 65536 Meanwhile: $ node -e "const { Stream } = require('stream'); s = process.stdout; s.write('@'.repeat(1280 * 1024)); Stream.finished(s, () => { process.exit(0); })" | wc -c 1310720 unknown|1 year ago [deleted] Thorrez|1 year ago You're not passing anything into the 2nd parameter of stdout.write()
3np|1 year ago
unknown|1 year ago
[deleted]
Thorrez|1 year ago