Using rxdart
's flatMap
with maxConcurrent
to limit the number of concurrent requests.
Author: Petrus Nguyễn Thái Học
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);