Node.js Nodejs阻塞直到异步调用完成?
如何让nodejs应用程序等待异步调用完成 梅因:咖啡:Node.js Nodejs阻塞直到异步调用完成?,node.js,coffeescript,async.js,Node.js,Coffeescript,Async.js,如何让nodejs应用程序等待异步调用完成 梅因:咖啡: 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
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
如果像“coffee main.coffee”这样运行,它将在执行工作之前退出 您没有调用所需的
async.each
回调
data = {}
async.each hosts, (host, cb_e) ->
dns.lookup host, (err, address, family) ->
data[host] = address
cb_e(err)
, () ->
console.log data
您没有调用所需的
async.each
回调
data = {}
async.each hosts, (host, cb_e) ->
dns.lookup host, (err, address, family) ->
data[host] = address
cb_e(err)
, () ->
console.log data
重复:通常,它会等待。当您只执行一次查找时会发生什么情况?重复:通常,它会等待。如果只执行一次查找,会发生什么情况?