【发布时间】:2014-05-04 17:41:07
【问题描述】:
我有两个由 Bluebird 运行的任务:
// Require bluebird...
var Promise = require("bluebird");
// Run two tasks together
Promise
.all([Git.getRemotes(), GitFtp.getFtpRemotes()])
.spread(function (remotes, ftpRemotes) {
// Something cool
});
使用 q.js 我得到了回应:
remotes.value (the response of my task)
remotes.state ("fullfilled" or "rejected" depending if the task thrown an error or not)
ftpRemotes.value
ftpRemotes.state
所以在spread() 部分中,我能够检查每个任务的状态。
This is the code I was using before Bluebird
有了蓝鸟,我得到了:
remotes
ftpRemotes
仅包含我的任务生成的数组。
我想我需要Promise.allSettled,但我在文档中找不到它。
如何获取每个任务的状态?
【问题讨论】:
-
如果你想让事情失败,你可以使用
Promise.settle,但我怀疑这就是你真正需要的。 -
这两个函数只为每个返回一个数组,我认为这无关紧要。顺便说一下源代码在这个 PR github.com/zaggino/brackets-git/pull/288
-
“我有回应”是什么意思?那是一些日志吗?在哪里?
-
q 如果特定任务顺利,则在“value”键中返回“fullfilled”字符串,如果出现问题则返回“rejected”。
-
@FezVrasta:你没有使用
Q.all,而是Q.allSettled,是吗?
标签: javascript promise bluebird