Logo FSharp.Core

ValueTask Module

Contains camelCase module-level functions for ValueTask computations.

Functions and values

Function or value Description

ValueTask.bind binder task

Full Usage: ValueTask.bind binder task

Parameters:
    binder : 'T -> ValueTask<'U> - A function that takes the result of the value task and returns a new value task.
    task : ValueTask<'T> - The input value task.

Returns: ValueTask<'U> A value task that performs a monadic bind on the result of task.
Modifiers: inline
Type parameters: 'T, 'U

Creates a value task that passes the result of the given value task to the binder function.

binder : 'T -> ValueTask<'U>

A function that takes the result of the value task and returns a new value task.

task : ValueTask<'T>

The input value task.

Returns: ValueTask<'U>

A value task that performs a monadic bind on the result of task.

Example

 let vt = ValueTask.result 21 |> ValueTask.bind (fun x -> ValueTask.result (x * 2))
 vt.Result // evaluates to 42
val vt: obj

ValueTask.catch task

Full Usage: ValueTask.catch task

Parameters:
    task : ValueTask<'T> - The input ValueTask.

Returns: ValueTask<Result<'T, exn>> A ValueTask that yields a Result: Ok with the outcome on success, or Error with the exception on failure. Propagates the underlying cancellation exception when task is canceled.
Type parameters: 'T

Creates a ValueTask that reifies the outcome of the given ValueTask as a Result: Ok on success, Error on failure, so faults become values. Cancellation still propagates.

OperationCanceledException and derived types such as TaskCanceledException propagate unchanged (and the task remains Canceled) in order to maintain cancellation semantics.

task : ValueTask<'T>

The input ValueTask.

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

A ValueTask that yields a Result: Ok with the outcome on success, or Error with the exception on failure. Propagates the underlying cancellation exception when task is canceled.

Example

 let safeDiv x y = task { return x / y } |> ValueTask.ofTask |> ValueTask.catch
 (safeDiv 10 2).Result // evaluates to Ok 5
 (safeDiv 10 0).Result // evaluates to Error (DivideByZeroException ...)
val safeDiv: x: int -> y: int -> 'a
val x: int
val y: int
val task: TaskBuilder
Multiple items
module Result from Microsoft.FSharp.Core

--------------------
type Result<'T,'TError> = | Ok of ResultValue: 'T | Error of ErrorValue: 'TError

ValueTask.catchWith handler task

Full Usage: ValueTask.catchWith handler task

Parameters:
    handler : exn -> 'T - A function to handle (non-cancellation) exceptions, yielding a recovery value based on the exception. Any exception thrown by handler will propagate.
    task : ValueTask<'T> - The input ValueTask.

Returns: ValueTask<'T> A ValueTask that yields the result of task on success, or handler exn on failure. Propagates the underlying cancellation exception when task is canceled.
Modifiers: inline
Type parameters: 'T

Creates a ValueTask that yields the original result on success, or the result of handler exn for non-cancellation exceptions.

OperationCanceledException and derived types such as TaskCanceledException propagate unchanged (and the task remains Canceled) in order to maintain cancellation semantics, and therefore are never passed to handler.

handler : exn -> 'T

A function to handle (non-cancellation) exceptions, yielding a recovery value based on the exception. Any exception thrown by handler will propagate.

task : ValueTask<'T>

The input ValueTask.

Returns: ValueTask<'T>

A ValueTask that yields the result of task on success, or handler exn on failure. Propagates the underlying cancellation exception when task is canceled.

Example

 let safeDiv x y =
     task { return x / y }
     |> ValueTask.ofTask
     |> ValueTask.catchWith (fun _ -> 0)
 (safeDiv 10 0).Result // evaluates to 0
val safeDiv: x: int -> y: int -> 'a
val x: int
val y: int
val task: TaskBuilder
Multiple items
module Result from Microsoft.FSharp.Core

--------------------
type Result<'T,'TError> = | Ok of ResultValue: 'T | Error of ErrorValue: 'TError

ValueTask.empty

Full Usage: ValueTask.empty

Returns: ValueTask<unit>

A completed value task that returns unit.

Returns: ValueTask<unit>
Example

 ValueTask.empty.Result // evaluates to ()

ValueTask.ignore task

Full Usage: ValueTask.ignore task

Parameters:
    task : ValueTask<'T> - The input value task.

Returns: ValueTask<unit> A value task that is equivalent to the input value task, but disregards the result.
Modifiers: inline
Type parameters: 'T

Creates a value task that runs the given value task and ignores its result.

When the value task is already synchronously complete, this avoids allocating a Task.

task : ValueTask<'T>

The input value task.

Returns: ValueTask<unit>

A value task that is equivalent to the input value task, but disregards the result.

Example

 let vt : ValueTask<unit> = ValueTask.result 42 |> ValueTask.ignore<int>
 vt.Result // evaluates to ()
val vt: obj
type unit = Unit
Multiple items
val int: value: 'T -> int (requires member op_Explicit)

--------------------
type int = int32

--------------------
type int<'Measure> = int

ValueTask.map mapping task

Full Usage: ValueTask.map mapping task

Parameters:
    mapping : 'T -> 'U - The function to apply to the result.
    task : ValueTask<'T> - The input value task.

Returns: ValueTask<'U> A value task that applies mapping to the result of task.
Modifiers: inline
Type parameters: 'T, 'U

Creates a value task that applies the mapping function to the result of the given value task.

mapping : 'T -> 'U

The function to apply to the result.

task : ValueTask<'T>

The input value task.

Returns: ValueTask<'U>

A value task that applies mapping to the result of task.

Example

 let vt = ValueTask.result 21 |> ValueTask.map (fun x -> x * 2)
 vt.Result // evaluates to 42
val vt: obj

ValueTask.ofTask task

Full Usage: ValueTask.ofTask task

Parameters:
    task : Task<'T> - The input task.

Returns: ValueTask<'T> A value task equivalent to the given task.
Modifiers: inline
Type parameters: 'T

Converts a Task to a ValueTask.

task : Task<'T>

The input task.

Returns: ValueTask<'T>

A value task equivalent to the given task.

Example

 let t = Task.FromResult 42
 let vt = ValueTask.ofTask t
 vt.Result // evaluates to 42
val t: obj
val vt: obj

ValueTask.result value

Full Usage: ValueTask.result value

Parameters:
    value : 'T - The value to return.

Returns: ValueTask<'T> A completed value task that returns value.
Modifiers: inline
Type parameters: 'T

Creates a value task that returns the given value.

value : 'T

The value to return.

Returns: ValueTask<'T>

A completed value task that returns value.

Example

 let vt = ValueTask.result 42
 vt.Result // evaluates to 42
val vt: obj

Type something to start searching.