与请求承诺异步

时间:2018-09-13 13:08:23

标签: javascript node.js async.js request-promise

一旦前一个请求完成,我需要迭代http请求。我正在使用请求承诺以及异步js。我的片段是

const _getAllProduct = (token, cb) => {
    const _condition = () => last !== true;
    const recordCount = 50;
    let last = false;
    let currentPage = 0;

    console.log(`\n2. Getting All Products`);
    let options = {
        headers: {'Content-Type': 'application/json'},
        json: true
    };
    let allProducts = [];
    const _iterate = callback => {
        options.url = `${domain.url}/all?page=${currentPage}&size=${recordCount}`;
        console.log(`Options: ${JSON.stringify(options)}`);
        console.log(`Here`);

        rp(options)
            .then(res => {
                last = res.last;
                allProducts = _.concat(allProducts, res.content);
                currentPage++;
                  callback(null, true);
            })
            .catch(error => callback(error));
    };

    async.whilst(_condition, _iterate, error => {
        if (error) return cb(error);
        console.log(`Total %d records fetched from domain`, allProducts ? _.size(allProducts) : 0);
        return cb(null, allProducts);
    });
};

问题是请求完成后,我会收到警告。警告是承诺创建的,但不返回。我的规范和要求正在使用async.jsrequest-promise模块。

(node:4159)警告:在/home/xavient/Desktop/node/kwa/syncing/utils/product-synb-job.js:65:8的处理程序中创建了一个承诺,但未从中返回,请参阅     在新的Promise(/home/xavient/Desktop/node/kwa/syncing/node_modules/bluebird/js/release/promise.js:79:10)

0 个答案:

没有答案