Task<S, F> extension type

A deferred operation that produces a Result each time it is run.

Nothing happens until run, and every call runs the operation again.

on

Constructors

Task(FutureOr<Res<S, F>> run())
A deferred operation that produces a Result each time it is run.
Task.attempt({required FutureOr<S> run(), required F handle(Object e)})
Runs a function that may throw, catching a throw as a Failure.
Task.fail(F value, [Object? exception, StackTrace? stack])
Creates a task that fails with the given value and an optional exception and stack trace, for stubbing in tests:
Task.succeed(S value)
Creates a task that succeeds with the given value, for stubbing in tests:

Methods

apply<S2, F2>(Res<S2, F2> onRun(Res<S, F> re)) → Task<S2, F2>
Maps the whole Result.
chain<S2>(Task<S2, F> task(S ok)) → Task<S2, F>
Runs the task built from the success value. A failure skips it.
chainStream<S2>(ResStream<S2, F> stream(S ok)) → ResStream<S2, F>
Starts the result stream built from the success value.
convert<S2>(S2 onOk(S ok)) → Task<S2, F>
Maps the success value. A failure passes through.
convertBoth<S2, F2>({required S2 onOk(S ok), required F2 onErr(F err)}) → Task<S2, F2>
Maps the success value and the failure value.
convertErr<F2>(F2 onErr(F err)) → Task<S, F2>
Maps the failure value. A success passes through.
ensure({required bool check(S ok), required F otherwise(S ok)}) → Task<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)}) → Task<S, F>
Turns a failure that passes check into a success of then(failure).
run() → FutureOr<Res<S, F>>
Runs the task and returns its Result.
then<S2>(FutureOr<Res<S2, F>> run(S ok)) → Task<S2, F>
Runs a function that returns a Result with the success value. A failure skips it.
thenAttempt<S2>({required FutureOr<S2> run(S ok), required F handle(Object e)}) → Task<S2, F>
Runs a function that may throw with the success value, catching a throw as Task.attempt does. A failure skips it.
thenAttemptStream<S2>({required Stream<S2> run(S ok), required F handle(Object e)}) → ResStream<S2, F>
Starts the plain stream built from the success value, catching its errors as ResultStream.attempt does. Otherwise it behaves like chainStream.