Is it safe to listen to the event AFTER registration?

I am new to NodeJS and I am learning how it works with threads. While reading the book, I found this code example:

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 piece of code, we call the method http.getand then expect a callback ( Part 1 ).

On the next line, we listen to the event total( Part 2 ).

Question: What should I do if there is a delay between the first and second parts, so the first call goes to the first (before part 2 starts listening to the event total. Will the data fragment be lost?

+4
source share
1 answer

, "" . http.get. 2 ( 1).

( ), .

. Javascript/ Node, : , ?.

+2

All Articles