RaceStream<T> class

Given two or more source streams, emit all of the items from only the first of these streams to emit an item or notification.

If the provided streams is empty, the resulting sequence completes immediately without emitting any items.

Interactive marble diagram

Example

RaceStream([
  TimerStream(1, Duration(days: 1)),
  TimerStream(2, Duration(days: 2)),
  TimerStream(3, Duration(seconds: 3))
]).listen(print); // prints 3
Inheritance
Available extensions

Constructors

RaceStream(Iterable<Stream<T>> streams)
Constructs a Stream which emits all events from a single Stream inside streams. The selected Stream is the first one which emits an event. After this event, all other Streams in streams are discarded.

Properties

first Future<T>
The first element of this stream.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
isBroadcast bool
Whether this stream is a broadcast stream.
no setterinherited
isEmpty Future<bool>
Whether this stream contains any elements.
no setterinherited
last Future<T>
The last element of this stream.
no setterinherited
length Future<int>
The number of elements in this stream.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
single Future<T>
The single element of this stream.
no setterinherited

Methods

any(bool test(T element)) Future<bool>
Checks whether test accepts any element provided by this stream.
inherited
asBroadcastStream({void onListen(StreamSubscription<T> subscription)?, void onCancel(StreamSubscription<T> subscription)?}) Stream<T>
Returns a multi-subscription stream that produces the same events as this.
inherited
asyncExpand<E>(Stream<E>? convert(T event)) Stream<E>
Transforms each element into a sequence of asynchronous events.
inherited
asyncMap<E>(FutureOr<E> convert(T event)) Stream<E>
Creates a new stream with each data event of this stream asynchronously mapped to a new event.
inherited
buffer(Stream<void> window) Stream<List<T>>

Available on Stream<T>, provided by the BufferExtensions extension

Creates a Stream where each item is a List containing the items from the source sequence.
bufferCount(int count, [int startBufferEvery = 0]) Stream<List<T>>

Available on Stream<T>, provided by the BufferExtensions extension

Buffers a number of values from the source Stream by count then emits the buffer and clears it, and starts a new buffer each startBufferEvery values. If startBufferEvery is not provided, then new buffers are started immediately at the start of the source and when each buffer closes and is emitted.
bufferTest(bool onTestHandler(T event)) Stream<List<T>>

Available on Stream<T>, provided by the BufferExtensions extension

Creates a Stream where each item is a List containing the items from the source sequence, batched whenever test passes.
bufferTime(Duration duration) Stream<List<T>>

Available on Stream<T>, provided by the BufferExtensions extension

Creates a Stream where each item is a List containing the items from the source sequence, sampled on a time frame with duration.
cast<R>() Stream<R>
Adapt this stream to be a Stream<R>.
inherited
concatWith(Iterable<Stream<T>> other) Stream<T>

Available on Stream<T>, provided by the ConcatExtensions extension

Returns a Stream that emits all items from the current Stream, then emits all items from the given streams, one after the next.
contains(Object? needle) Future<bool>
Returns whether needle occurs in the elements provided by this stream.
inherited
debounce(Stream<void> window(T event)) Stream<T>

Available on Stream<T>, provided by the DebounceExtensions extension

Transforms a Stream so that will only emit items from the source sequence if a window has completed, without the source sequence emitting another item.
debounceTime(Duration duration) Stream<T>

Available on Stream<T>, provided by the DebounceExtensions extension

Transforms a Stream so that will only emit items from the source sequence whenever the time span defined by duration passes, without the source sequence emitting another item.
defaultIfEmpty(T defaultValue) Stream<T>

Available on Stream<T>, provided by the DefaultIfEmptyExtension extension

Emit items from the source Stream, or a single default item if the source Stream emits nothing.
delay(Duration duration) Stream<T>

Available on Stream<T>, provided by the DelayExtension extension

The Delay operator modifies its source Stream by pausing for a particular increment of time (that you specify) before emitting each of the source Stream’s items. This has the effect of shifting the entire sequence of items emitted by the Stream forward in time by that specified increment.
delayWhen(Stream<void> itemDelaySelector(T value), {Stream<void>? listenDelay}) Stream<T>

Available on Stream<T>, provided by the DelayWhenExtension extension

Delays the emission of items from the source Stream by a given time span determined by the emissions of another Stream.
dematerialize() Stream<T>

Available on Stream<StreamNotification<T>>, provided by the DematerializeExtension extension

Converts the onData, onDone, and onError StreamNotification objects from a materialized stream into normal onData, onDone, and onError events.
distinct([bool equals(T previous, T next)?]) Stream<T>
Skips data events if they are equal to the previous data event.
inherited
distinctUnique({bool equals(T e1, T e2)?, int hashCode(T e)?}) Stream<T>

Available on Stream<T>, provided by the DistinctUniqueExtension extension

WARNING: More commonly known as distinct in other Rx implementations. Creates a Stream where data events are skipped if they have already been emitted before.
doOnCancel(FutureOr<void> onCancel()) Stream<T>

Available on Stream<T>, provided by the DoExtensions extension

Invokes the given callback function when the stream subscription is cancelled. Often called doOnUnsubscribe or doOnDispose in other implementations.
doOnData(void onData(T event)) Stream<T>

Available on Stream<T>, provided by the DoExtensions extension

Invokes the given callback function when the stream emits an item. In other implementations, this is called doOnNext.
doOnDone(void onDone()) Stream<T>

Available on Stream<T>, provided by the DoExtensions extension

Invokes the given callback function when the stream finishes emitting items. In other implementations, this is called doOnComplete(d).
doOnEach(void onEach(StreamNotification<T> notification)) Stream<T>

Available on Stream<T>, provided by the DoExtensions extension

Invokes the given callback function when the stream emits data, emits an error, or emits done. The callback receives a StreamNotification object.
doOnError(void onError(Object, StackTrace)) Stream<T>

Available on Stream<T>, provided by the DoExtensions extension

Invokes the given callback function when the stream emits an error.
doOnListen(void onListen()) Stream<T>

Available on Stream<T>, provided by the DoExtensions extension

Invokes the given callback function when the stream is first listened to.
doOnPause(void onPause()) Stream<T>

Available on Stream<T>, provided by the DoExtensions extension

Invokes the given callback function when the stream subscription is paused.
doOnResume(void onResume()) Stream<T>

Available on Stream<T>, provided by the DoExtensions extension

Invokes the given callback function when the stream subscription resumes receiving items.
drain<E>([E? futureValue]) Future<E>
Discards all data on this stream, but signals when it is done or an error occurred.
inherited
elementAt(int index) Future<T>
Returns the value of the indexth data event of this stream.
inherited
endWith(T endValue) Stream<T>

Available on Stream<T>, provided by the EndWithExtension extension

Appends a value to the source Stream before closing.
endWithMany(Iterable<T> endValues) Stream<T>

Available on Stream<T>, provided by the EndWithManyExtension extension

Appends a sequence of values as final events to the source Stream before closing.
every(bool test(T element)) Future<bool>
Checks whether test accepts all elements provided by this stream.
inherited
exhaustMap<S>(Stream<S> mapper(T value)) Stream<S>

Available on Stream<T>, provided by the ExhaustMapExtension extension

Converts items from the source stream into a Stream using a given mapper. It ignores all items from the source stream until the new stream completes.
expand<S>(Iterable<S> convert(T element)) Stream<S>
Transforms each element of this stream into a sequence of elements.
inherited
firstWhere(bool test(T element), {T orElse()?}) Future<T>
Finds the first element of this stream matching test.
inherited
flatMap<S>(Stream<S> mapper(T value), {int? maxConcurrent}) Stream<S>

Available on Stream<T>, provided by the FlatMapExtension extension

Converts each emitted item into a Stream using the given mapper function, while limiting the maximum number of concurrent subscriptions to these Streams. The newly created Stream will be be listened to and begin emitting items downstream.
flatMapIterable<S>(Stream<Iterable<S>> mapper(T value), {int? maxConcurrent}) Stream<S>

Available on Stream<T>, provided by the FlatMapExtension extension

Converts each item into a Stream. The Stream must return an Iterable. Then, each item from the Iterable will be emitted one by one.
fold<S>(S initialValue, S combine(S previous, T element)) Future<S>
Combines a sequence of values by repeatedly applying combine.
inherited
forEach(void action(T element)) Future<void>
Executes action on each element of this stream.
inherited
groupBy<K>(K grouper(T value), {Stream<void> durationSelector(GroupedStream<T, K> grouped)?}) Stream<GroupedStream<T, K>>

Available on Stream<T>, provided by the GroupByExtension extension

The GroupBy operator divides a Stream that emits items into a Stream that emits GroupedStream, each one of which emits some subset of the items from the original source Stream.
handleError(Function onError, {bool test(dynamic error)?}) Stream<T>
Creates a wrapper Stream that intercepts some errors from this stream.
inherited
ignoreElements() Stream<Never>

Available on Stream<T>, provided by the IgnoreElementsExtension extension

Creates a Stream where all emitted items are ignored, only the error / completed notifications are passed
interval(Duration duration) Stream<T>

Available on Stream<T>, provided by the IntervalExtension extension

Creates a Stream that emits each item in the Stream after a given duration.
join([String separator = ""]) Future<String>
Combines the string representation of elements into a single string.
inherited
lastWhere(bool test(T element), {T orElse()?}) Future<T>
Finds the last element in this stream matching test.
inherited
listen(void onData(T value)?, {Function? onError, void onDone()?, bool? cancelOnError}) StreamSubscription<T>
Adds a subscription to this stream.
inherited
map<S>(S convert(T event)) Stream<S>
Transforms each element of this stream into a new stream event.
inherited
mapNotNull<R extends Object>(R? transform(T)) Stream<R>

Available on Stream<T>, provided by the MapNotNullExtension extension

Returns a Stream containing only the non-null results of applying the given transform function to each element of this Stream.
mapTo<T>(T value) Stream<T>

Available on Stream<S>, provided by the MapToExtension extension

Emits the given constant value on the output Stream every time the source Stream emits a value.
materialize() Stream<StreamNotification<T>>

Available on Stream<T>, provided by the MaterializeExtension extension

Converts the onData, on Done, and onError events into StreamNotification objects that are passed into the downstream onData listener.
max([Comparator<T>? comparator]) Future<T>

Available on Stream<T>, provided by the MaxExtension extension

Converts a Stream into a Future that completes with the largest item emitted by the Stream.
mergeWith(Iterable<Stream<T>> streams) Stream<T>

Available on Stream<T>, provided by the MergeExtension extension

Combines the items emitted by multiple streams into a single stream of items. The items are emitted in the order they are emitted by their sources.
min([Comparator<T>? comparator]) Future<T>

Available on Stream<T>, provided by the MinExtension extension

Converts a Stream into a Future that completes with the smallest item emitted by the Stream.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onErrorResume(Stream<T> recoveryFn(Object error, StackTrace stackTrace)) Stream<T>

Available on Stream<T>, provided by the OnErrorExtensions extension

Intercepts error events and switches to a recovery stream created by the provided recoveryFn.
onErrorResumeNext(Stream<T> recoveryStream) Stream<T>

Available on Stream<T>, provided by the OnErrorExtensions extension

Intercepts error events and switches to the given recovery stream in that case
onErrorReturn(T returnValue) Stream<T>

Available on Stream<T>, provided by the OnErrorExtensions extension

Instructs a Stream to emit a particular item when it encounters an error, and then terminate normally
onErrorReturnWith(T returnFn(Object error, StackTrace stackTrace)) Stream<T>

Available on Stream<T>, provided by the OnErrorExtensions extension

Instructs a Stream to emit a particular item created by the returnFn when it encounters an error, and then terminate normally.
pairwise() Stream<List<T>>

Available on Stream<T>, provided by the PairwiseExtension extension

Emits the n-th and n-1th events as a pair. The first event won't be emitted until the second one arrives.
pipe(StreamConsumer<T> streamConsumer) Future
Pipes the events of this stream into streamConsumer.
inherited
publish() PublishConnectableStream<T>

Available on Stream<T>, provided by the ConnectableStreamExtensions extension

Convert the current Stream into a ConnectableStream that can be listened to multiple times. It will not begin emitting items from the original Stream until the connect method is invoked.
publishReplay({int? maxSize}) ReplayConnectableStream<T>

Available on Stream<T>, provided by the ConnectableStreamExtensions extension

Convert the current Stream into a ReplayConnectableStream that can be listened to multiple times. It will not begin emitting items from the original Stream until the connect method is invoked.
publishValue() ValueConnectableStream<T>

Available on Stream<T>, provided by the ConnectableStreamExtensions extension

Convert the current Stream into a ValueConnectableStream that can be listened to multiple times. It will not begin emitting items from the original Stream until the connect method is invoked.
publishValueSeeded(T seedValue) ValueConnectableStream<T>

Available on Stream<T>, provided by the ConnectableStreamExtensions extension

Convert the current Stream into a ValueConnectableStream that can be listened to multiple times, providing an initial seeded value. It will not begin emitting items from the original Stream until the connect method is invoked.
reduce(T combine(T previous, T element)) Future<T>
Combines a sequence of values by repeatedly applying combine.
inherited
sample(Stream sampleStream) Stream<T>

Available on Stream<T>, provided by the SampleExtensions extension

Emits the most recently emitted item (if any) emitted by the source Stream since the previous emission from the sampleStream.
sampleTime(Duration duration) Stream<T>

Available on Stream<T>, provided by the SampleExtensions extension

Emits the most recently emitted item (if any) emitted by the source Stream since the previous emission within the recurring time span, defined by duration
scan<S>(S accumulator(S accumulated, T value, int index), S seed) Stream<S>

Available on Stream<T>, provided by the ScanExtension extension

Applies an accumulator function over a Stream sequence and returns each intermediate result. The seed value is used as the initial accumulator value.
share() Stream<T>

Available on Stream<T>, provided by the ConnectableStreamExtensions extension

Convert the current Stream into a new Stream that can be listened to multiple times. It will automatically begin emitting items when first listened to, and shut down when no listeners remain.
shareReplay({int? maxSize}) ReplayStream<T>

Available on Stream<T>, provided by the ConnectableStreamExtensions extension

Convert the current Stream into a new ReplayStream that can be listened to multiple times. It will automatically begin emitting items when first listened to, and shut down when no listeners remain.
shareValue() ValueStream<T>

Available on Stream<T>, provided by the ConnectableStreamExtensions extension

Convert the current Stream into a new ValueStream that can be listened to multiple times. It will automatically begin emitting items when first listened to, and shut down when no listeners remain.
shareValueSeeded(T seedValue) ValueStream<T>

Available on Stream<T>, provided by the ConnectableStreamExtensions extension

Convert the current Stream into a new ValueStream that can be listened to multiple times, providing an initial value. It will automatically begin emitting items when first listened to, and shut down when no listeners remain.
singleWhere(bool test(T element), {T orElse()?}) Future<T>
Finds the single element in this stream matching test.
inherited
skip(int count) Stream<T>
Skips the first count data events from this stream.
inherited
skipLast(int count) Stream<T>

Available on Stream<T>, provided by the SkipLastExtension extension

Starts emitting every items except last count items. This causes items to be delayed.
skipUntil<S>(Stream<S> otherStream) Stream<T>

Available on Stream<T>, provided by the SkipUntilExtension extension

Starts emitting items only after the given stream emits an item.
skipWhile(bool test(T element)) Stream<T>
Skip data events from this stream while they are matched by test.
inherited
startWith(T startValue) Stream<T>

Available on Stream<T>, provided by the StartWithExtension extension

Prepends a value to the source Stream.
startWithMany(List<T> startValues) Stream<T>

Available on Stream<T>, provided by the StartWithManyExtension extension

Prepends a sequence of values to the source Stream.
switchIfEmpty(Stream<T> fallbackStream) Stream<T>

Available on Stream<T>, provided by the SwitchIfEmptyExtension extension

When the original Stream emits no items, this operator subscribes to the given fallback stream and emits items from that Stream instead.
switchMap<S>(Stream<S> mapper(T value)) Stream<S>

Available on Stream<T>, provided by the SwitchMapExtension extension

Converts each emitted item into a Stream using the given mapper function. The newly created Stream will be be listened to and begin emitting items, and any previously created Stream will stop emitting.
take(int count) Stream<T>
Provides at most the first count data events of this stream.
inherited
takeLast(int count) Stream<T>

Available on Stream<T>, provided by the TakeLastExtension extension

Emits only the final count values emitted by the source Stream.
takeUntil<S>(Stream<S> otherStream) Stream<T>

Available on Stream<T>, provided by the TakeUntilExtension extension

Returns the values from the source Stream sequence until the other Stream sequence produces a value.
takeWhile(bool test(T element)) Stream<T>
Forwards data events while test is successful.
inherited
takeWhileInclusive(bool test(T)) Stream<T>

Available on Stream<T>, provided by the TakeWhileInclusiveExtension extension

Emits values emitted by the source Stream so long as each value satisfies the given test. When the test is not satisfied by a value, it will emit this value as a final event and then complete.
throttle(Stream<void> window(T event), {bool trailing = false, bool leading = true}) Stream<T>

Available on Stream<T>, provided by the ThrottleExtensions extension

Emits a value from the source Stream, then ignores subsequent source values while the window Stream is open, then repeats this process.
throttleTime(Duration duration, {bool trailing = false, bool leading = true}) Stream<T>

Available on Stream<T>, provided by the ThrottleExtensions extension

Emits a value from the source Stream, then ignores subsequent source values for a duration, then repeats this process.
timeInterval() Stream<TimeInterval<T>>

Available on Stream<T>, provided by the TimeIntervalExtension extension

Records the time interval between consecutive values in a Stream sequence.
timeout(Duration timeLimit, {void onTimeout(EventSink<T> sink)?}) Stream<T>
Creates a new stream with the same events as this stream.
inherited
timestamp() Stream<Timestamped<T>>

Available on Stream<T>, provided by the TimeStampExtension extension

Wraps each item emitted by the source Stream in a Timestamped object that includes the emitted item and the time when the item was emitted.
toList() Future<List<T>>
Collects all elements of this stream in a List.
inherited
toSet() Future<Set<T>>
Collects the data of this stream in a Set.
inherited
toString() String
A string representation of this object.
inherited
transform<S>(StreamTransformer<T, S> streamTransformer) Stream<S>
Applies streamTransformer to this stream.
inherited
where(bool test(T event)) Stream<T>
Creates a new stream from this stream that discards some elements.
inherited
whereNotNull() Stream<T>

Available on Stream<T?>, provided by the WhereNotNullExtension extension

Returns a Stream which emits all the non-null elements of this Stream, in their original emission order.
whereType<S>() Stream<S>

Available on Stream<T>, provided by the WhereTypeExtension extension

This transformer is a shorthand for Stream.where followed by Stream.cast.
window(Stream<void> window) Stream<Stream<T>>

Available on Stream<T>, provided by the WindowExtensions extension

Creates a Stream where each item is a Stream containing the items from the source sequence.
windowCount(int count, [int startBufferEvery = 0]) Stream<Stream<T>>

Available on Stream<T>, provided by the WindowExtensions extension

Buffers a number of values from the source Stream by count then emits the buffer as a Stream and clears it, and starts a new buffer each startBufferEvery values. If startBufferEvery is not provided, then new buffers are started immediately at the start of the source and when each buffer closes and is emitted.
windowTest(bool onTestHandler(T event)) Stream<Stream<T>>

Available on Stream<T>, provided by the WindowExtensions extension

Creates a Stream where each item is a Stream containing the items from the source sequence, batched whenever test passes.
windowTime(Duration duration) Stream<Stream<T>>

Available on Stream<T>, provided by the WindowExtensions extension

Creates a Stream where each item is a Stream containing the items from the source sequence, sampled on a time frame with duration.
withLatestFrom<S, R>(Stream<S> latestFromStream, R fn(T t, S s)) Stream<R>

Available on Stream<T>, provided by the WithLatestFromExtensions extension

Creates a Stream that emits when the source stream emits, combining the latest values from the two streams using the provided function.
withLatestFrom2<A, B, R>(Stream<A> latestFromStream1, Stream<B> latestFromStream2, R fn(T t, A a, B b)) Stream<R>

Available on Stream<T>, provided by the WithLatestFromExtensions extension

Creates a Stream that emits when the source stream emits, combining the latest values from the three streams using the provided function.
withLatestFrom3<A, B, C, R>(Stream<A> latestFromStream1, Stream<B> latestFromStream2, Stream<C> latestFromStream3, R fn(T t, A a, B b, C c)) Stream<R>

Available on Stream<T>, provided by the WithLatestFromExtensions extension

Creates a Stream that emits when the source stream emits, combining the latest values from the four streams using the provided function.
withLatestFrom4<A, B, C, D, R>(Stream<A> latestFromStream1, Stream<B> latestFromStream2, Stream<C> latestFromStream3, Stream<D> latestFromStream4, R fn(T t, A a, B b, C c, D d)) Stream<R>

Available on Stream<T>, provided by the WithLatestFromExtensions extension

Creates a Stream that emits when the source stream emits, combining the latest values from the five streams using the provided function.
withLatestFrom5<A, B, C, D, E, R>(Stream<A> latestFromStream1, Stream<B> latestFromStream2, Stream<C> latestFromStream3, Stream<D> latestFromStream4, Stream<E> latestFromStream5, R fn(T t, A a, B b, C c, D d, E e)) Stream<R>

Available on Stream<T>, provided by the WithLatestFromExtensions extension

Creates a Stream that emits when the source stream emits, combining the latest values from the six streams using the provided function.
withLatestFrom6<A, B, C, D, E, F, R>(Stream<A> latestFromStream1, Stream<B> latestFromStream2, Stream<C> latestFromStream3, Stream<D> latestFromStream4, Stream<E> latestFromStream5, Stream<F> latestFromStream6, R fn(T t, A a, B b, C c, D d, E e, F f)) Stream<R>

Available on Stream<T>, provided by the WithLatestFromExtensions extension

Creates a Stream that emits when the source stream emits, combining the latest values from the seven streams using the provided function.
withLatestFrom7<A, B, C, D, E, F, G, R>(Stream<A> latestFromStream1, Stream<B> latestFromStream2, Stream<C> latestFromStream3, Stream<D> latestFromStream4, Stream<E> latestFromStream5, Stream<F> latestFromStream6, Stream<G> latestFromStream7, R fn(T t, A a, B b, C c, D d, E e, F f, G g)) Stream<R>

Available on Stream<T>, provided by the WithLatestFromExtensions extension

Creates a Stream that emits when the source stream emits, combining the latest values from the eight streams using the provided function.
withLatestFrom8<A, B, C, D, E, F, G, H, R>(Stream<A> latestFromStream1, Stream<B> latestFromStream2, Stream<C> latestFromStream3, Stream<D> latestFromStream4, Stream<E> latestFromStream5, Stream<F> latestFromStream6, Stream<G> latestFromStream7, Stream<H> latestFromStream8, R fn(T t, A a, B b, C c, D d, E e, F f, G g, H h)) Stream<R>

Available on Stream<T>, provided by the WithLatestFromExtensions extension

Creates a Stream that emits when the source stream emits, combining the latest values from the nine streams using the provided function.
withLatestFrom9<A, B, C, D, E, F, G, H, I, R>(Stream<A> latestFromStream1, Stream<B> latestFromStream2, Stream<C> latestFromStream3, Stream<D> latestFromStream4, Stream<E> latestFromStream5, Stream<F> latestFromStream6, Stream<G> latestFromStream7, Stream<H> latestFromStream8, Stream<I> latestFromStream9, R fn(T t, A a, B b, C c, D d, E e, F f, G g, H h, I i)) Stream<R>

Available on Stream<T>, provided by the WithLatestFromExtensions extension

Creates a Stream that emits when the source stream emits, combining the latest values from the ten streams using the provided function.
withLatestFromList(Iterable<Stream<T>> latestFromStreams) Stream<List<T>>

Available on Stream<T>, provided by the WithLatestFromExtensions extension

Creates a Stream that emits when the source stream emits, combining the latest values from the streams into a list. This is helpful when you need to combine a dynamic number of Streams.
zipWith<S, R>(Stream<S> other, R zipper(T t, S s)) Stream<R>

Available on Stream<T>, provided by the ZipWithExtension extension

Returns a Stream that combines the current stream together with another stream using a given zipper function.

Operators

operator ==(Object other) bool
The equality operator.
inherited