I'm new to NodeJS, and I'm learning how it works with streams.
Reading a book I found this sample code:
var CountStream = require('./countstream');
var countStream = new CountStream('book');
var http = require('http');
http.get('http://www.manning.com', function(res) {
res.pipe(countStream);
});
countStream.on('total', function(count) {
console.log();
});
In this code snippet we're calling http.get
method and then waiting for the callback (Part 1).
On the next line we're listening for total
event (Part 2).
Question: What if a delay happens between Part 1 and Part 2, so the Part 1's callback executes first (before Part 2 starts listening to to total
event. Is it true that the first chunk(s) of data will be lost?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…