Task<S, F> extension type

Represents asynchronous tasks that can succeed or fail.

on

Constructors

Task(FutureOr<Res<S, F>> run())
Represents asynchronous tasks that can succeed or fail.
Task.attempt({required FutureOr<S> run(), required F handle(Object e)})
Attempts to execute an asynchronous function and captures any exceptions as failures.
Task.fail(F value, [Object? exception, StackTrace? stack])
Creates a task that immediately fails with the given value, exception, and stack trace.
Task.succeed(S value)
Creates a task that immediately succeeds with the given value.

Methods

apply<S2, F2>(Res<S2, F2> onRun(Res<S, F> re)) Task<S2, F2>
Applies a function to the result of the task, allowing for transformations of both success and failure values.
chain<S2>(Task<S2, F> task(S ok)) Task<S2, F>
Chains another task to be executed if the current task succeeds.
convert<S2>(S2 onOk(S ok)) Task<S2, F>
Converts the success type of the task's result.
convertBoth<S2, F2>({required S2 onOk(S ok), required F2 onErr(F err)}) Task<S2, F2>
Converts both the success and failure types of the task's result.
convertErr<F2>(F2 onErr(F err)) Task<S, F2>
Converts the failure type of the task's result.
ensure({required bool check(S ok), required F otherwise(S ok)}) Task<S, F>
Ensures that a success value satisfies a condition, otherwise converts it to a failure.
recoverWhen({required bool check(F err), required S then(F err)}) Task<S, F>
Recovers from a failure when a specified condition is met.
run() FutureOr<Res<S, F>>
Executes the task and returns a Future that completes with a Result containing either a success value of type S or a failure value of type F.
then<S2>(FutureOr<Res<S2, F>> run(S ok)) Task<S2, F>
Chains another asynchronous function to be executed if the current task succeeds.
thenAttempt<S2>({required FutureOr<S2> run(S ok), required F handle(Object e)}) Task<S2, F>
Chains another asynchronous function to be executed if the current task succeeds, while also catching any exceptions that may occur and converting them to failures.