【发布时间】:2012-11-02 06:38:06
【问题描述】:
我正在尝试让 Step.js 库与咖啡脚本一起正常工作。我对咖啡很陌生,但这是我的尝试:
setTimeout(
=>
console.log("step 1 at #{new Date}")
setTimeout(
=>
console.log("step 2 at #{new Date}")
setTimeout(
=>
console.log("step 3 at #{new Date}")
10000
)
10000
)
10000
)
# step 1 at Tue Nov 13 2012 13:18:51 GMT-0600 (CST)
# step 2 at Tue Nov 13 2012 13:19:01 GMT-0600 (CST)
# step 3 at Tue Nov 13 2012 13:19:11 GMT-0600 (CST)
应该与:
step(
->
setTimeout(
=>
console.log("step 1 at #{new Date}")
this(null)
10000
)
->
setTimeout(
=>
console.log("step 2 at #{new Date}")
this(null)
10000
)
->
setTimeout(
=>
console.log("step 3 at #{new Date}")
this(null)
10000
)
)
# step 1 at Tue Nov 13 2012 13:12:04 GMT-0600 (CST)
# step 2 at Tue Nov 13 2012 13:12:04 GMT-0600 (CST)
# step 3 at Tue Nov 13 2012 13:12:04 GMT-0600 (CST)
从上面的示例步骤中可以看出,步骤是同时执行所有步骤,而不是像预期的那样一次执行一个步骤。我不太清楚为什么会是现在。
【问题讨论】:
标签: node.js asynchronous coffeescript