Browse files

Add comment to makeAsync().

  • Loading branch information...
1 parent 1aed45e commit 528cd4a5d7397ab18bab61b34d89e4d30906ae54 @koichik committed Aug 24, 2011
Showing with 32 additions and 2 deletions.
  1. +16 −1 lib/dns_legacy.js
  2. +16 −1 lib/dns_uv.js
View
17 lib/dns_legacy.js
@@ -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,
+// 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;
View
17 lib/dns_uv.js
@@ -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;

0 comments on commit 528cd4a

Please sign in to comment.