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

Viewed 445

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.

1 Answers

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.
Related