Header menu logo IcedTasks

CancellableValueTask Module

Contains functional helper functions for composing and converting pooling-backed CancellableValueTask values.

Table of contents

Cancellation and Exceptions

Functions and values

Function or value Description

CancellableValueTask.getCancellationToken () ct

Full Usage: CancellableValueTask.getCancellationToken () ct

Parameters:
Returns: ValueTask<CancellationToken> The default CancellationToken.
Modifiers: inline

Gets the default cancellation token for executing computations.

() : unit
ct : CancellationToken
Returns: ValueTask<CancellationToken>

The default CancellationToken.

Example

 use tokenSource = new CancellationTokenSource()
 let primes = [ 2; 3; 5; 7; 11 ]
 for i in primes do
     let computation =
         cancellableValueTask {
             let! cancellationToken = CancellableValueTask.getCancellationToken()
             do! Task.Delay(i * 1000, cancellationToken)
             printfn $"{i}"
         }
     computation tokenSource.Token |> ignore
 Thread.Sleep(6000)
 tokenSource.Cancel()
 printfn "Tasks Finished"
val tokenSource: obj
val primes: int list
val i: int
val computation: (obj -> obj)
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
val ignore: value: 'T -> unit
This will print "2" 2 seconds from start, "3" 3 seconds from start, "5" 5 seconds from start, cease computation and then followed by "Tasks Finished".

Other module members

Functions and values

Function or value Description

CancellableValueTask.apply applicable cTask

Full Usage: CancellableValueTask.apply applicable cTask

Parameters:
Returns: CancellableValueTask<'output> The result of the applicable.
Modifiers: inline
Type parameters: 'input, 'output

Allows chaining of CancellableValueTasks.

applicable : CancellableValueTask<('input -> 'output)>

A function wrapped in a CancellableValueTasks

cTask : CancellableValueTask<'input>

The value.

Returns: CancellableValueTask<'output>

The result of the applicable.

CancellableValueTask.bind binder cTask

Full Usage: CancellableValueTask.bind binder cTask

Parameters:
Returns: CancellableValueTask<'output> The result of the binder.
Modifiers: inline
Type parameters: 'input, 'output

Allows chaining of CancellableValueTasks.

binder : 'input -> CancellableValueTask<'output>

The continuation.

cTask : CancellableValueTask<'input>

The value.

Returns: CancellableValueTask<'output>

The result of the binder.

CancellableValueTask.map mapper cTask

Full Usage: CancellableValueTask.map mapper cTask

Parameters:
Returns: CancellableValueTask<'output> The result of the mapper wrapped in a CancellableValueTasks.
Modifiers: inline
Type parameters: 'input, 'output

Allows chaining of CancellableValueTasks.

mapper : 'input -> 'output

The continuation.

cTask : CancellableValueTask<'input>

The value.

Returns: CancellableValueTask<'output>

The result of the mapper wrapped in a CancellableValueTasks.

CancellableValueTask.ofUnit unitCancellableTask

Full Usage: CancellableValueTask.ofUnit unitCancellableTask

Parameters:
Returns: CancellableValueTask<unit> A CancellableValueTask\ that completes when unitCancellableTask completes.
Modifiers: inline

Converts a non-generic CancellableValueTask to a CancellableValueTask\.

unitCancellableTask : CancellableValueTask

The CancellableValueTask to convert.

Returns: CancellableValueTask<unit>

A CancellableValueTask\ that completes when unitCancellableTask completes.

CancellableValueTask.parallelZip left right

Full Usage: CancellableValueTask.parallelZip left right

Parameters:
Returns: CancellableValueTask<'left * 'right> A tuple of the parameters passed in.
Modifiers: inline
Type parameters: 'left, 'right

Takes two CancellableValueTasks, starts them concurrently with the same cancellation token, and returns a tuple of the pair.

left : CancellableValueTask<'left>

The left value.

right : CancellableValueTask<'right>

The right value.

Returns: CancellableValueTask<'left * 'right>

A tuple of the parameters passed in.

Example

 let both =
     CancellableValueTask.parallelZip firstOperation secondOperation

 let! left, right = both cancellationToken |> Async.AwaitValueTask
val both: obj
Multiple items
type Async = static member AsBeginEnd: computation: ('Arg -> Async<'T>) -> ('Arg * AsyncCallback * obj -> IAsyncResult) * (IAsyncResult -> 'T) * (IAsyncResult -> unit) static member AwaitEvent: event: IEvent<'Del,'T> * ?cancelAction: (unit -> unit) -> Async<'T> (requires delegate and 'Del :> Delegate) static member AwaitIAsyncResult: iar: IAsyncResult * ?millisecondsTimeout: int -> Async<bool> static member AwaitTask: task: Task<'T> -> Async<'T> + 1 overload static member AwaitWaitHandle: waitHandle: WaitHandle * ?millisecondsTimeout: int -> Async<bool> static member CancelDefaultToken: unit -> unit static member Catch: computation: Async<'T> -> Async<Choice<'T,exn>> static member Choice: computations: Async<'T option> seq -> Async<'T option> static member FromBeginEnd: beginAction: (AsyncCallback * obj -> IAsyncResult) * endAction: (IAsyncResult -> 'T) * ?cancelAction: (unit -> unit) -> Async<'T> + 3 overloads static member FromContinuations: callback: (('T -> unit) * (exn -> unit) * (OperationCanceledException -> unit) -> unit) -> Async<'T> ...

--------------------
type Async<'T>

CancellableValueTask.singleton item ct

Full Usage: CancellableValueTask.singleton item ct

Parameters:
    item : 'item - The item to be the result of the CancellableValueTask.
    ct : CancellationToken

Returns: ValueTask<'item> A CancellableValueTask with the item as the result.
Modifiers: inline
Type parameters: 'item

Lifts an item to a CancellableValueTask.

item : 'item

The item to be the result of the CancellableValueTask.

ct : CancellationToken
Returns: ValueTask<'item>

A CancellableValueTask with the item as the result.

CancellableValueTask.toUnit cancellableTask ct

Full Usage: CancellableValueTask.toUnit cancellableTask ct

Parameters:
Returns: ValueTask A non-generic CancellableValueTask that completes when cancellableTask completes.
Modifiers: inline
Type parameters: 'a

Converts a CancellableValueTask\<_> to a non-generic CancellableValueTask by discarding the result.

cancellableTask : CancellableValueTask<'a>

The CancellableValueTask to convert.

ct : CancellationToken
Returns: ValueTask

A non-generic CancellableValueTask that completes when cancellableTask completes.

CancellableValueTask.zip left right

Full Usage: CancellableValueTask.zip left right

Parameters:
Returns: CancellableValueTask<'left * 'right> A tuple of the parameters passed in
Modifiers: inline
Type parameters: 'left, 'right

Takes two CancellableValueTasks, starts them serially in order of left to right, and returns a tuple of the pair.

left : CancellableValueTask<'left>

The left value.

right : CancellableValueTask<'right>

The right value.

Returns: CancellableValueTask<'left * 'right>

A tuple of the parameters passed in

Type something to start searching.