【发布时间】:2012-10-14 13:52:32
【问题描述】:
当调用'/a'时,'/b'可以立即执行。但是如果我调用另一个'/a',第二个会等待第一个结束。如何让 '/a' 真正异步调用?
代码:
app.get '/a', (req, res, next) ->
f = ->
res.send 'a'
console.log 'end', new Date()
console.log 'sleep', new Date()
setTimeout f, 10000
app.get '/b', (req, res, next) ->
res.send 'b'
输出:
Express server listening on port 3000 in development mode
sleep Sun Oct 14 2012 12:37:52 GMT+0800 (SGT)
GET /b 200 9ms - 1
end Sun Oct 14 2012 12:38:02 GMT+0800 (SGT)
GET /a 200 10022ms - 1
sleep Sun Oct 14 2012 12:38:02 GMT+0800 (SGT)
end Sun Oct 14 2012 12:38:12 GMT+0800 (SGT)
GET /a 200 10005ms - 1
【问题讨论】: