'Flutter Dio Is there a way to set a limit on the number of concurrent requests

I use Dio for networking in Flutter.

I tried to find a way to set the maximum number of concurrent requests. I looked to BaseOptions and RequestOptions, but it seems there's no option.

How can I set that? Thank you.



Solution 1:[1]

It seems that there is no option related to limit of concurrent requests.

But I have a one idea to implement concurrent request limit by using 'QueuedInterceptor' .
(I am not sure that it works well)
https://github.com/flutterchina/dio#queuedinterceptor

I think that add a interceptor to dio instance and can control request and response count.

  1. Add a 'QueuedInterceptor' interceptor at dio instance.
  2. At 'onRequest' callback in 'QueuedInterceptor', increase current requested request counter.
    If requested request counter overs limit of request, reject a request with some error.
  3. At 'onResponse' callback in 'QueuedInterceptor', decrease current requested request counter.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 KuKu