Task
Index
Constructor
create
Type parameters
- Value
- Error = never
reject
Constructor that always returns a failed
Task
that rejectserror
. This is a shorthand forTask(({ error }) => error(errorValue))
Type parameters
- Value = never
resolve
Constructor that always returns a successful
Task
that resolvesvalue
. This is a shorthand forTask(({ ok }) => ok(value))
Type parameters
- Error = never
Type
hasInstance
Return
true
if anyValue is a validTask
Other
ErrorOf
Extracts error type of task T
Type parameters
- T
ValueOf
Extracts value type of task T
Type parameters
- T
all
Resolves with the array of all task values, or reject with the first error
Type parameters
- T: readonly TaskLike<any, any>[]
allSettled
Resolves an array of all task results
Type parameters
- T: TaskLike<any, any>[]
andRun
Similar to andThen but the task keep
task
resolved valueType parameters
- ValueFrom
- ErrorFrom
- ErrorTo
andThen
Calls
fn
if the task is successful, otherwise returns the failed task untouched. This function can be used for control flow based onTask
values.Type parameters
- ValueFrom
- ErrorFrom
- ValueTo
- ErrorTo
any
Resolves with the first value, or reject with an aggregated error
Type parameters
- T: TaskLike<any, any>[]
from
Create a Task from a
taskRun
function or a TaskLikeType parameters
- Value
- Error
ignore
Ignores value of task
Type parameters
- Error
map
Maps a
Task<Value, Error>
toTask<NewValue, Error>
by applying a function to a success value, leaving a failure untouched. This function can be used to compose the results of two functions.Type parameters
- ValueFrom
- ErrorFrom
- ValueTo
mapError
Maps a
Task<Value, ErrorFrom>
toTask<Value, ErrorTo>
by applying a function to a contained failure error, leaving a success value untouched. This function can be used to pass through a successful result while handling an error.Type parameters
- ValueFrom
- ErrorFrom
- ErrorTo
mapResult
Maps a
Task<ValueFrom, ErrorFrom>
toTask<ValueTo, ErrorTo>
by applying a function to the result of the task.Type parameters
- ValueFrom
- ErrorFrom
- ValueTo
- ErrorTo
orElse
Calls
fn
if the task is failed, otherwise returns the successful task untouched. This function can be used for control flow based onTask
values.Type parameters
- ValueFrom
- ErrorFrom
- ValueTo
- ErrorTo
run
Run
task
and return the result or a promise of the result⚠ Impure function that may throw an error, it should be used on the edge of the program.
Type parameters
- Value
- Error
tryCall
Creates a new
Task
that resolvessideEffect()
. When an exception is thrown then it rejectsonError([thrown error])
.Type parameters
- Value
- Error = never
Task constructor