Skip to content

Using `rxdart`'s `flatMap` with `maxConcurrent` to limit the number of concurrent requests.

Notifications You must be signed in to change notification settings

hoc081098/rxdart_flatmap_max_concurrent

Repository files navigation

rxdart_flatmap_max_concurrent

Using rxdart's flatMap with maxConcurrent to limit the number of concurrent requests.

Hits

Stream<void> sendRequest(_Entry entry) {
  print('SimpleClient: --> ${entry.request.url}');

  return _client
      .send(entry.request)
      .asStream()
      .doOnError(entry.completer.completeError)
      .doOnData(entry.completer.complete)
      .onErrorResumeNext(Stream.empty())
      .doOnCancel(() => print('SimpleClient: <-- ${entry.request.url}'));
}

// Use [flatMap] from `rxdart` to limit the number of concurrent requests easily :))
requestController.stream
    .flatMap(sendRequest, maxConcurrent: maxConcurrent)
    .listen(null);