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

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

问题描述

假设我有10个网址,我希望为每个网址发出HTTP请求。

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

我可以创建一个可观察的网址,然后 .flatMap()每个请求,然后 .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

推荐答案

这个问题的答案如下:如何限制平面图的并发性
你也可以在这里查看答案并行激发异步请求,但使用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天全站免登陆