I'm adding a lot of domain names into async.queue (https://github.com/caolan/async), then doing dns lookups. For some reason the drain event from the async library is being called too soon, either right at the start of the queue or soon after. I want to know when the queue is actually finished so I can use the results.
If someone can recommend another library or method to queue jobs I don't need to use this async library, I just want to get this working.
const dns = require('dns');
const async = require('async');
const MaxConcurrent = 2; // only do x DNS lookups at one time
const MaxWait = 1000; // wait for a second before dns timeout
var dnsQueue = async.queue(function(domain, lookupAgain) {
setTimeout(
function() {
dns.resolve(domain, function (err, address)
{
console.log('domain: ' + domain + " address: " + address)
});
lookupAgain();
}, MaxWait);
}, MaxConcurrent);
// This should run when the queue is finished
dnsQueue.drain = function() {
console.log('done??');
}
// Array of domain names
var uniqueDomains = [
'google.com',
'yahoo.com',
'ask.com',
'cnn.com',
'real.com'
];
// Push each domain name into the dnsQueue
uniqueDomains.forEach(function(domain) {
dnsQueue.push(domain);
});
from Detect when async.queue finished
No comments:
Post a Comment