ResStream<S, F> extension type

A deferred source that emits a sequence of Results each time it is run.

Failures are data: a Failure never ends the stream. Operators apply to each result as it arrives. An operator callback that throws turns that event into an untyped stream error, and later events keep flowing. Untyped stream errors pass through every operator.

on

Constructors

ResStream(Stream<Res<S, F>> stream())
A deferred source that emits a sequence of Results each time it is run.
ResStream.attempt({required Stream<S> run(), required F handle(Object e)})
Wraps a stream of plain values, catching its errors as failures.
ResStream.fail(F value, [Object? exception, StackTrace? stack])
Creates a result stream that emits one failure with the given value and an optional exception and stack trace, then closes. For stubbing in tests:
ResStream.fromResults(Iterable<Res<S, F>> results)
Creates a result stream that emits the given results in order, then closes. For stubbing in tests:
ResStream.fromTask(Task<S, F> task)
Creates a result stream that emits the task's Result, then closes.
ResStream.succeed(S value)
Creates a result stream that emits one success with the given value, then closes. For stubbing in tests:

Methods

apply<S2, F2>(Res<S2, F2> onRun(Res<S, F> re)) → ResStream<S2, F2>
Maps each whole Result.
chain<S2>(Task<S2, F> task(S ok)) → ResStream<S2, F>
Runs the task built from each success value. Failures skip it.
chainStream<S2>(ResStream<S2, F> stream(S ok)) → ResStream<S2, F>
Switches to the result stream built from each success value.
combineWith<B, S2>(ResStream<B, F> other, {required S2 combine(S a, B b)}) → ResStream<S2, F>
Combines the latest success of this stream and the others with combine.
combineWithFive<B, C, D, E, G, S2>((ResStream<B, F>, ResStream<C, F>, ResStream<D, F>, ResStream<E, F>, ResStream<G, F>) others, {required S2 combine(S a, B b, C c, D d, E e, G g)}) → ResStream<S2, F>
Combines the latest success of this stream and the others with combine.
combineWithFour<B, C, D, E, S2>((ResStream<B, F>, ResStream<C, F>, ResStream<D, F>, ResStream<E, F>) others, {required S2 combine(S a, B b, C c, D d, E e)}) → ResStream<S2, F>
Combines the latest success of this stream and the others with combine.
combineWithThree<B, C, D, S2>((ResStream<B, F>, ResStream<C, F>, ResStream<D, F>) others, {required S2 combine(S a, B b, C c, D d)}) → ResStream<S2, F>
Combines the latest success of this stream and the others with combine.
combineWithTwo<B, C, S2>((ResStream<B, F>, ResStream<C, F>) others, {required S2 combine(S a, B b, C c)}) → ResStream<S2, F>
Combines the latest success of this stream and the others with combine.
convert<S2>(S2 onOk(S ok)) → ResStream<S2, F>
Maps the success value. A failure passes through.
convertBoth<S2, F2>({required S2 onOk(S ok), required F2 onErr(F err)}) → ResStream<S2, F2>
Maps the success value and the failure value.
convertErr<F2>(F2 onErr(F err)) → ResStream<S, F2>
Maps the failure value. A success passes through.
ensure({required bool check(S ok), required F otherwise(S ok)}) → ResStream<S, F>
Turns a success that fails check into a failure of otherwise(success).
recoverWhen({required bool check(F err), required S then(F err)}) → ResStream<S, F>
Turns a failure that passes check into a success of then(failure).
restartWhen({bool onErr(F err, int attempt)?, bool onClose(int attempt)?, Duration delay(int attempt)?, bool hideErr = true}) → ResStream<S, F>
Cancels the source and runs it again when onFailure or onClose returns true, such as to reconnect a dropped websocket feed.
run() → Stream<Res<S, F>>
Runs the source and returns its stream of Results.
then<S2>(FutureOr<Res<S2, F>> run(S ok)) → ResStream<S2, F>
Runs a function that returns a Result with each success value. Failures skip it.
thenAttempt<S2>({required FutureOr<S2> run(S ok), required F handle(Object e)}) → ResStream<S2, F>
Runs a function that may throw with each success value, catching a throw as Task.attempt does. Failures skip it.
thenAttemptStream<S2>({required Stream<S2> run(S ok), required F handle(Object e)}) → ResStream<S2, F>
Switches to the plain stream built from each success value, catching its errors as ResultStream.attempt does. Otherwise it behaves like chainStream.
transform<S2, F2>(StreamTransformer<Res<S, F>, Res<S2, F2>> transformer) → ResStream<S2, F2>
Applies a StreamTransformer to the results, for stream-shaped behaviour such as distinct, take or debouncing.
untilErr() → ResStream<S, F>
Emits results up to and including the first failure, then closes and cancels the source. Untyped stream errors don't stop it.