/rxdart_flatmap_max_concurrent

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

Primary LanguageDart

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);