使用 RxJS 限制一次请求的数量 [英] Limit number of requests at a time with RxJS

查看:25
本文介绍了使用 RxJS 限制一次请求的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有 10 个 url,我希望为每个 url 发出 HTTP 请求.

Suppose I have 10 urls, and I wish to make an HTTP request for each one of them.

我可以创建一个可观察的 URL,然后 .flatMap() 对每个 URL 的请求,然后 .subscribe 对结果.但这会同时发出所有请求.

I could create an observable of the URLs, then .flatMap() the requests for each one of them, and then .subscribe for the results. But that would make all of the requests at once.

有没有办法将请求的数量限制为固定数量,以免服务器过载

Is there a way to impose a limit to the number of requests to a fixed number, in order not to overload the server

推荐答案

这个问题在这里有答案:如何限制平面地图的并发性您还可以在此处查看答案 Fire并行异步请求但使用 rxjs 按顺序获取结果

This question has an answer here : how-to-limit-the-concurrency-of-flatmap You can also review the answer here Fire async request in parallel but get result in order using rxjs

基本上它围绕使用 merge(withMaxConcurrency) 操作符.

Basically it revolves around using the merge(withMaxConcurrency) operator.

这篇关于使用 RxJS 限制一次请求的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆