【发布时间】:2017-06-22 02:18:06
【问题描述】:
我无法理解如何将单个 Promise 调整为在两个 API 调用都返回后解决的 Promise 链。
如何将下面的代码重写为一系列 Promise?
function parseTweet(tweet) {
indico.sentimentHQ(tweet)
.then(function(res) {
tweetObj.sentiment = res;
}).catch(function(err) {
console.warn(err);
});
indico.organizations(tweet)
.then(function(res) {
tweetObj.organization = res[0].text;
tweetObj.confidence = res[0].confidence;
}).catch(function(err) {
console.warn(err);
});
}
谢谢。
【问题讨论】:
标签: javascript node.js