【发布时间】:2015-02-07 00:37:42
【问题描述】:
给定以下 Coffeescript 代码:
for groupID, groupObj of @cache.groups
#do some other stuff
#calling this function which is returning a promise
@callcounter.findNumbers(groupID)
.then (result) =>
@cache.groups[groupID].someValue = result.someValue
在幕后,findNumbers 方法正在查询 SQL 数据库(使用繁琐,不支持并发查询)并返回一个 Promise(库:Q)
因此,代码执行不会进入for-loop 的下一次迭代,直到前一次的承诺得到解决。
你会如何以正确的方式做到这一点?
【问题讨论】:
-
请问为什么这个问题被否决了?
标签: node.js coffeescript q