Header menu logo TDesu.FSharp

Task Module

Task combinators — map, bind, zip, catch, and more for Task{T}.

All functions are inline for zero-overhead abstractions. Thread-safe by design.

Functions and values

Function or value Description

asUnit t

Full Usage: asUnit t

Parameters:
Returns: Task<unit>
Modifiers: inline

Converts a non-generic Task to Task<unit>. The non-generic task to convert.

t : Task
Returns: Task<unit>

bind f t

Full Usage: bind f t

Parameters:
Returns: Task<'TResult>
Modifiers: inline
Type parameters: 'T, 'TResult

Chains a task-returning function on the result of a task. The binding function returning a new task. The input task.

f : 'T -> Task<'TResult>
t : Task<'T>
Returns: Task<'TResult>

catch t

Full Usage: catch t

Parameters:
    t : Task<'T> - The task to execute inside a try/catch.

Returns: Task<Result<'T, exn>>
Modifiers: inline
Type parameters: 'T

Runs a task inside a try/catch, returning Ok on success or Error(exn) on failure.

t : Task<'T>

The task to execute inside a try/catch.

Returns: Task<Result<'T, exn>>

fireAndForget onError f

Full Usage: fireAndForget onError f

Parameters:
    onError : exn -> unit - Callback invoked with the exception if the task faults.
    f : unit -> Task - Factory that produces the task to run.

Modifiers: inline

Fire-and-forget: starts a task without awaiting. Logs exceptions via onError.

onError should not throw; if it does, the exception is silently swallowed.

onError : exn -> unit

Callback invoked with the exception if the task faults.

f : unit -> Task

Factory that produces the task to run.

getResult t

Full Usage: getResult t

Parameters:
Returns: 'a
Modifiers: inline
Type parameters: 'a

Synchronously gets the result of a Task (ConfigureAwait false). The task whose result to retrieve.

t : Task<'a>
Returns: 'a

ignore t

Full Usage: ignore t

Parameters:
Returns: Task<unit>
Modifiers: inline
Type parameters: 'a

Discards the task result, returning Task<unit>. The task whose result to discard.

t : Task<'a>
Returns: Task<unit>

map f t

Full Usage: map f t

Parameters:
    f : 'T -> 'TResult
    t : Task<'T>

Returns: Task<'TResult>
Modifiers: inline
Type parameters: 'T, 'TResult

Maps the result of a task with the given function. The mapping function. The input task.

f : 'T -> 'TResult
t : Task<'T>
Returns: Task<'TResult>

map2 f t1 t2

Full Usage: map2 f t1 t2

Parameters:
    f : 'T1 -> 'T2 -> 'TResult
    t1 : Task<'T1>
    t2 : Task<'T2>

Returns: Task<'TResult>
Modifiers: inline
Type parameters: 'T1, 'T2, 'TResult

Maps a function over two task results, running them concurrently. The mapping function taking two values. The first task. The second task.

f : 'T1 -> 'T2 -> 'TResult
t1 : Task<'T1>
t2 : Task<'T2>
Returns: Task<'TResult>

parallelThrottle maxConcurrent items f

Full Usage: parallelThrottle maxConcurrent items f

Parameters:
    maxConcurrent : int - Maximum number of tasks allowed to run concurrently.
    items : 'T seq - The input sequence of items to process.
    f : 'T -> Task<'TResult> - Async function applied to each item.

Returns: Task<'TResult[]>

Runs tasks in parallel with a throttle (max concurrent). Returns all results.

On Fable, runs without throttling (JS is single-threaded).

maxConcurrent : int

Maximum number of tasks allowed to run concurrently.

items : 'T seq

The input sequence of items to process.

f : 'T -> Task<'TResult>

Async function applied to each item.

Returns: Task<'TResult[]>

parallelThrottleUnit maxConcurrent items f

Full Usage: parallelThrottleUnit maxConcurrent items f

Parameters:
    maxConcurrent : int
    items : 'T seq
    f : 'T -> Task<unit>

Returns: Task<unit>

Runs tasks in parallel with a throttle, ignoring results. Maximum number of tasks allowed to run concurrently. The input sequence of items to process. Async function applied to each item.

maxConcurrent : int
items : 'T seq
f : 'T -> Task<unit>
Returns: Task<unit>

runSynchronously t

Full Usage: runSynchronously t

Parameters:
    t : 'a

Blocks until the task completes (ConfigureAwait false). No-op if null or already completed. The task to wait on.

t : 'a

singleton v

Full Usage: singleton v

Parameters:
    v : 'T

Returns: Task<'T>
Modifiers: inline
Type parameters: 'T

Wraps a value in a completed task. The value to wrap.

v : 'T
Returns: Task<'T>

waitUntil timeout condition

Full Usage: waitUntil timeout condition

Parameters:
    timeout : TimeSpan - Maximum duration to wait.
    condition : unit -> bool - Predicate polled until it returns true.

Returns: Task<bool>

Polls a condition with short delays until it returns true or timeout is reached. Returns true if condition was met, false on timeout.

timeout : TimeSpan

Maximum duration to wait.

condition : unit -> bool

Predicate polled until it returns true.

Returns: Task<bool>

zip t1 t2

Full Usage: zip t1 t2

Parameters:
Returns: Task<'T1 * 'T2>
Modifiers: inline
Type parameters: 'T1, 'T2

Combines two tasks into a tuple, running them concurrently. The first task. The second task.

t1 : Task<'T1>
t2 : Task<'T2>
Returns: Task<'T1 * 'T2>

zip3 t1 t2 t3

Full Usage: zip3 t1 t2 t3

Parameters:
Returns: Task<'T1 * 'T2 * 'T3>
Modifiers: inline
Type parameters: 'T1, 'T2, 'T3

Combines three tasks into a triple, running them concurrently. The first task. The second task. The third task.

t1 : Task<'T1>
t2 : Task<'T2>
t3 : Task<'T3>
Returns: Task<'T1 * 'T2 * 'T3>

Type something to start searching.