Skip to content

Commit

Permalink
Additional refinement / tweaking
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Apr 19, 2016
1 parent 3066845 commit 4571b86
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,21 +215,20 @@ exports.lookupService = function(host, port, callback) {

function onresolve(err, result) {
const emitter = this.emitter;
if (err) {
process.nextTick(() => {
process.nextTick(() => {
if (err) {
emitter.emit('error',
errnoException(err, this.bindingName, this.hostname));
});
} else {
process.nextTick(() => {
} else {
emitter.emit('resolve', result);
});
}
// Decrement the outstanding resolve counter.
_resolvesOutstanding--;
}
});
// This has to be done on setImmediate in order to give c-ares
// time to cleanup after the resolve completes.
setImmediate(() => emitter.emit('complete'));
setImmediate(() => {
_resolvesOutstanding--;
emitter.emit('complete');
});
}

class Resolver extends EventEmitter {
Expand All @@ -240,7 +239,7 @@ class Resolver extends EventEmitter {
throw new Error('"name" argument must be a string');
}
// Do this on nextTick in order to give users time to
// attach the on 'complete' listener.
// attach the listeners.
process.nextTick(() => {
var req = new QueryReqWrap();
req.bindingName = bindingName;
Expand All @@ -258,8 +257,8 @@ class Resolver extends EventEmitter {
}
var err = binding(req, name);
if (err) {
_resolvesOutstanding--;
req.emitter.emit('error', errnoException(err, bindingName));
_resolvesOutstanding--;
}
});
}
Expand Down

0 comments on commit 4571b86

Please sign in to comment.