繁体   English   中英

承诺返回undefined

[英]Promise returns undefined

我知道你不能让异步函数同步运行但是如何在我的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);
});
};

我调用上面的方法如下。 但是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=....

尝试从第一个回调中返回承诺

movieCheck.getToken()
    .then(function (token) {
    return movieCheck.movieCheck(token);
}).then(function (movies) {
    console.log(movies); //should print json data
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM