I have a loop like this:
var req;
for (var i=0; i<sites.length; i++) {
req = https.get(sites[i], handleRequest);
req.on('error', handleError);
}
The callback (handleRequest
) runs asynchronously, for each website being requested.
However, the only parameter in handleRequest seems to be a "response". When the callback is run, the loop has already completed, so how can I keep track of which website is this response for, so I can handle it accordingly?