Header menu logo IcedTasks

CancellableTask Module

Contains functional helper functions for composing and converting CancellableTask values.

Table of contents

Cancellation and Exceptions

Functions and values

Function or value Description

CancellableTask.getCancellationToken () ct

Full Usage: CancellableTask.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 =
         cancellableTask {
             let! cancellationToken = CancellableTask.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

CancellableTask.apply applicable cTask

Full Usage: CancellableTask.apply applicable cTask

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

Allows chaining of CancellableTasks.

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

A function wrapped in a CancellableTasks

cTask : CancellableTask<'input>

The value.

Returns: CancellableTask<'output>

The result of the applicable.

CancellableTask.bind binder cTask

Full Usage: CancellableTask.bind binder cTask

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

Allows chaining of CancellableTasks.

binder : 'input -> CancellableTask<'output>

The continuation.

cTask : CancellableTask<'input>

The value.

Returns: CancellableTask<'output>

The result of the binder.

CancellableTask.map mapper cTask

Full Usage: CancellableTask.map mapper cTask

Parameters:
    mapper : 'input -> 'output - The continuation.
    cTask : CancellableTask<'input> - The value.

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

Allows chaining of CancellableTasks.

mapper : 'input -> 'output

The continuation.

cTask : CancellableTask<'input>

The value.

Returns: CancellableTask<'output>

The result of the mapper wrapped in a CancellableTasks.

CancellableTask.ofUnit unitCancellableTask

Full Usage: CancellableTask.ofUnit unitCancellableTask

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

Converts a non-generic CancellableTask to a CancellableTask\.

unitCancellableTask : CancellableTask

The CancellableTask to convert.

Returns: CancellableTask<unit>

A CancellableTask\ that completes when unitCancellableTask completes.

CancellableTask.parallelZip left right

Full Usage: CancellableTask.parallelZip left right

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

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

left : CancellableTask<'left>

The left value.

right : CancellableTask<'right>

The right value.

Returns: CancellableTask<'left * 'right>

A tuple of the parameters passed in.

Example

 let both =
     CancellableTask.parallelZip firstOperation secondOperation

 let! left, right = both cancellationToken
val both: obj

CancellableTask.sequential tasks

Full Usage: CancellableTask.sequential tasks

Parameters:
Returns: CancellableTask<'a array> A CancellableTask that represents the completion of all of the supplied tasks.
Modifiers: inline
Type parameters: 'a

Creates a CancellableTask that will complete when all of the CancellableTasks in an enumerable collection have completed sequentially.

tasks : CancellableTask<'a> seq

The tasks to wait on for completion

Returns: CancellableTask<'a array>

A CancellableTask that represents the completion of all of the supplied tasks.

CancellableTask.singleton item arg2

Full Usage: CancellableTask.singleton item arg2

Parameters:
    item : 'item - The item to be the result of the CancellableTask.
    arg1 : CancellationToken

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

Lifts an item to a CancellableTask.

item : 'item

The item to be the result of the CancellableTask.

arg1 : CancellationToken
Returns: Task<'item>

A CancellableTask with the item as the result.

CancellableTask.toUnit ctask ct

Full Usage: CancellableTask.toUnit ctask ct

Parameters:
Returns: Task A non-generic CancellableTask that completes when ctask completes.
Modifiers: inline
Type parameters: 'a

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

ctask : CancellableTask<'a>

The CancellableTask to convert.

ct : CancellationToken
Returns: Task

A non-generic CancellableTask that completes when ctask completes.

CancellableTask.whenAll tasks

Full Usage: CancellableTask.whenAll tasks

Parameters:
Returns: CancellableTask<'a[]> A CancellableTask that represents the completion of all of the supplied tasks.
Modifiers: inline
Type parameters: 'a

Creates a task that will complete when all of the CancellableTask values in an enumerable collection have completed.

tasks : CancellableTask<'a> seq

The tasks to wait on for completion

Returns: CancellableTask<'a[]>

A CancellableTask that represents the completion of all of the supplied tasks.

ArgumentNullException The tasks argument was .
ArgumentException The tasks collection contained a task.

CancellableTask.whenAllThrottled maxDegreeOfParallelism tasks

Full Usage: CancellableTask.whenAllThrottled maxDegreeOfParallelism tasks

Parameters:
    maxDegreeOfParallelism : int - The maximum number of tasks to run concurrently.
    tasks : CancellableTask<'a> seq - The tasks to wait on for completion

Returns: CancellableTask<'a[]> A CancellableTask that represents the completion of all of the supplied tasks.
Modifiers: inline
Type parameters: 'a

Creates a task that runs the supplied CancellableTasks with a maximum degree of parallelism and completes when all have completed.

maxDegreeOfParallelism : int

The maximum number of tasks to run concurrently.

tasks : CancellableTask<'a> seq

The tasks to wait on for completion

Returns: CancellableTask<'a[]>

A CancellableTask that represents the completion of all of the supplied tasks.

ArgumentNullException The tasks argument was .
ArgumentException The tasks collection contained a task.
Example

 let loadAll ids =
     ids
     |> Seq.map loadOne
     |> CancellableTask.whenAllThrottled 4
val loadAll: ids: 'a seq -> 'b
val ids: 'a seq
module Seq from Microsoft.FSharp.Collections
val map: mapping: ('T -> 'U) -> source: 'T seq -> 'U seq

CancellableTask.zip left right

Full Usage: CancellableTask.zip left right

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

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

left : CancellableTask<'left>

The left value.

right : CancellableTask<'right>

The right value.

Returns: CancellableTask<'left * 'right>

A tuple of the parameters passed in

Type something to start searching.