【发布时间】:2019-03-25 18:00:44
【问题描述】:
在一个 express 项目中,我有 2 个地图,它们都通过 puppeteer 实例运行并且都返回数组。目前,我正在使用 Promise.all 等待两个地图完成,但它只返回第一个数组的值,而不是第二个数组。我该怎么做才能获得两个地图变量的结果?
const games = JSON.parse(JSON.stringify(req.body.games));
const queue = new PQueue({
concurrency: 2
});
const f = games.map((g) => queue.add(async () => firstSearch(g.game, g.categories)));
const s = games.map((g) => queue.add(async () => secondSearch(g.game, g.categories)));
return Promise.all(f, s)
.then(function(g) {
console.log(g); //only returns `f` result, not the `s`
});
【问题讨论】:
标签: javascript node.js express promise bluebird