Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Add comment to makeAsync().
Browse files Browse the repository at this point in the history
  • Loading branch information
koichik committed Aug 23, 2011
1 parent 1aed45e commit 528cd4a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
17 changes: 16 additions & 1 deletion lib/dns_legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,22 @@ var channel = new dns.Channel({SOCK_STATE_CB: function(socket, read, write) {
updateTimer();
}});

// Make sure that the callback is invoked asynchronously.
// c-ares invokes a callback both synchronously and asynchronously,

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis Aug 23, 2011

Member

both = either? It suggests the callback is run twice. Otherwise LGTM.

This comment has been minimized.

Copy link
@koichik

koichik Aug 23, 2011

Author

@bnoordhuis - Thanks!
yes, I mean is either. Thanks again.

// but the dns API should always invoke a callback asynchronously.
//
// This function makes sure that the callback is invoked asynchronously.
// It returns a function that invokes the callback within nextTick().
//
// To avoid invoking unnecessary nextTick(), `immediately` property of
// returned function should be set to true after c-ares returned.
//
// Usage:
//
// function someAPI(callback) {
// callback = makeAsync(callback);
// channel.someAPI(..., callback);
// callback.immediately = true;
// }
function makeAsync(callback) {
if (typeof callback !== 'function') {
return callback;
Expand Down
17 changes: 16 additions & 1 deletion lib/dns_uv.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,22 @@ function symToFamily(family) {
}
}

// Make sure that the callback is invoked asynchronously.
// c-ares invokes a callback both synchronously and asynchronously,
// but the dns API should always invoke a callback asynchronously.
//
// This function makes sure that the callback is invoked asynchronously.
// It returns a function that invokes the callback within nextTick().
//
// To avoid invoking unnecessary nextTick(), `immediately` property of
// returned function should be set to true after c-ares returned.
//
// Usage:
//
// function someAPI(callback) {
// callback = makeAsync(callback);
// channel.someAPI(..., callback);
// callback.immediately = true;
// }
function makeAsync(callback) {
if (typeof callback !== 'function') {
return callback;
Expand Down

0 comments on commit 528cd4a

Please sign in to comment.