从promise链函数返回module.export的响应

时间:2016-09-23 17:54:58

标签: javascript node.js promise

我有一个功能链,前提是完美的。但是,我仍然不明白这一切是如何工作的,而且我可以访问数据的唯一方法是:

listArticles(int pageIdx, int pageMax)
.flatMapIterable(list->list)
.flatMap(article ->
     getUserByUserIds(article.userId)
     .subscribeOn(Schedulers.io())
     .flatMapIterable(list->list),
     Pair::of
)
.toList();

当我尝试传递参数而不是getAxiosUrls() .then(getNbShares) .then(console.log) 时,错误为console.log。那么如何通过以下方式传递argument is not defined响应:

(console.log)

我正在使用快递,所以最后我需要做const my_data = function(req, res) { //probably something else here return res.send(response); }

module.exports

如果所有这些声音混淆,我很抱歉。我还在学习,并且仍然因承诺,回调和请求方法而感到困惑。

如果需要,这是我承诺的功能:

首先:

module.exports = {
    my_data
};

第二:

const getAxiosUrls = function() { 
    return axios.get("http://localhost:3000/gatable")
      .then(function (response) {
          return urls = response.data.rows.map( ([x, y, z]) => y )
    })
}

然后:

const getNbShares = function() {
    return Promise.map(urls, requestPromise)
        .map((htmlOnePage, index) => {
            const $ = cheerio.load(htmlOnePage);
            const share = $('.nb-shares').html();
            let shareTuple = {};
                shareTuple[urls[index]] = share;
                return shareTuple;
        })
        .catch((e) => console.log('We encountered an error' + e));
}

1 个答案:

答案 0 :(得分:0)

好的,所以我最终想出了这个:

const shares = function(req, res) {
    return getAxiosUrls()
   .then(getNbShares)
   .then(function (response, error) {
    return res.send(response);;
});}