Skip to content

Instantly share code, notes, and snippets.

@michaelficarra
Created July 19, 2011 03:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelficarra/1091267 to your computer and use it in GitHub Desktop.
Save michaelficarra/1091267 to your computer and use it in GitHub Desktop.
another TameJS example rewritten in imaginary-coffeescript-with-defer
{resolve} = require "dns"
do_one = (host, cb) ->
(err, ip) <- resolve host, "A", *
console.log if err then "ERROR! #{err}" else "#{host} -> #{ip}"
cb() if typeof cb is 'function'
do_all = (hosts) ->
defer
for host, i in hosts
do_one host, null
return
do_all process.argv[2..]
var dns = require("dns");
function do_one (ev, host) {
var err, ip;
twait { dns.resolve (host, "A", mkevent (err, ip));}
if (err) { console.log ("ERROR! " + err); }
else { console.log (host + " -> " + ip); }
ev();
}
function do_all (lst) {
twait {
for (var i = 0; i < lst.length; i++) {
do_one (mkevent (), lst[i]);
}
}
}
do_all (process.argv.slice (2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment