Reputation: 5317
How would one make a nodejs application wait for async calls to finish?
main.coffee:
hosts = require './suhosts'
dns = require 'dns'
async = require 'async'
data = {}
async.each hosts, (host, cb_e) ->
dns.lookup host, (err, address, family)-> data[host] = address
, () ->
console.log data
if one runs this like coffee main.coffee
it will exit before doing the work.
Upvotes: 0
Views: 281
Reputation: 225238
You’re not calling the required async.each
callback.
data = {}
async.each hosts, (host, cb_e) ->
dns.lookup host, (err, address, family) ->
data[host] = address
cb_e(err)
, () ->
console.log data
Upvotes: 2