**已关闭。**此问题需要debugging details。当前不接受答案。
编辑问题以包括desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答问题。
昨天关门了。
Improve this question
假设我请求一个url,它返回最大页数,即5。然后我需要请求第2页,第3页,第4页和第5页。
然而,为了不被阻塞,这些不能同时完成,而是顺序完成,所以Promise.all()
不会工作(如果我理解正确的话)。
如果我事先知道我必须获得多少页面,我可以只链.then
s,但我只在第一次请求后获得信息。
来自所有请求的数据也必须被收集、处理并传递给另一个函数。
我怀疑这与承诺有关,但如何正确地将它们联系起来,我无能为力。
2条答案
按热度按时间3qpi33ja1#
您可以通过定义
Promise.resolve()
并在每次迭代中链接它来顺序地获取请求。另一种方式:使用异步等待
bsxbgnwa2#
您可以使用类似
p-limit
的工具手动执行此操作示例: