StreamingFutureBatcher<T>.from constructor
StreamingFutureBatcher<T>.from (
- Iterable<
BatchedFutureGenerator< generators,T> > - int threadCount, {
- bool closeWhenIdle = true,
Creates a batcher from an iterable of generators.
Creating a batcher in this way allows the stream to close automatically
when everything has completed. This behaviour is set with closeWhenIdle
.
When closeWhenIdle
is true, this can be a drop-in replacement for
[Stream.fromFutures).
closeWhenIdle
can also be changed at any point before closing.
Implementation
StreamingFutureBatcher.from(
Iterable<BatchedFutureGenerator<T>> generators,
int threadCount, {
bool closeWhenIdle = true,
}) : _closeWhenIdle = closeWhenIdle,
super(threadCount) {
// Add the initial generators.
addAll(generators);
// Close immediately if there were no initial generators and closeWhenIdle
// is true.
if (_totalResultCount == 0 && closeWhenIdle) close();
}