【发布时间】:2015-09-27 17:00:03
【问题描述】:
我知道你不能让异步函数同步运行,但是 如何在我的承诺链中添加某种订单?
一个结果依赖于先前的承诺值,当这种情况没有发生时,我得到一个未定义的错误。这是一个 http 请求,因此它依赖于外部因素,例如我的连接执行请求的速度等。
module.exports.movieCheck = function(authToken) {
return request({
method : 'GET',
uri : 'https://graph.facebook.com/' + profileID + '/posts?fields=message&limit=25&' + authToken
}).spread(function (response, body) {
console.log('https://graph.facebook.com/' + profileID + '/posts?fields=message&limit=25&' + authToken);
return body;
}, function(e) {
console.log(e);
});
};
我调用上面的方法如下。但是 console.log 返回 undefined。
movieCheck.getToken()
.then(function(token) {
movieCheck.movieCheck(token);
})
.then(function(movies) {
console.log(movies); //should print json data
});
终端打印
undefined
https://graph.facebook.com/.../posts?fields=message&limit=25&access_token=....
【问题讨论】:
标签: javascript node.js promise bluebird