mgr*_*mgr 3 javascript node.js promise bluebird
我知道你不能让异步函数同步运行但是如何在我的promises链中添加某种顺序?
一个结果依赖于先前的promise值,当没有发生时,我得到一个未定义的错误.这是一个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);
});
};
Run Code Online (Sandbox Code Playgroud)
我调用上面的方法如下.但是console.log返回undefined.
movieCheck.getToken()
.then(function(token) {
movieCheck.movieCheck(token);
})
.then(function(movies) {
console.log(movies); //should print json data
});
Run Code Online (Sandbox Code Playgroud)
终端打印
undefined
https://graph.facebook.com/.../posts?fields=message&limit=25&access_token=....
Run Code Online (Sandbox Code Playgroud)
尝试从第一个回调中返回承诺
movieCheck.getToken()
.then(function (token) {
return movieCheck.movieCheck(token);
}).then(function (movies) {
console.log(movies); //should print json data
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4986 次 |
| 最近记录: |