Header menu logo TDesu.FSharp

TaskGroup Type

Structured concurrency: run multiple tasks, cancel all on first failure. Similar to Go's errgroup.

Example

 use group = new TaskGroup()
 let mutable user = Unchecked.defaultof<_>
 let mutable orders = Unchecked.defaultof<_>
 group.Run(fun ct -> task { let! u = fetchUser ct in user <- u })
 group.Run(fun ct -> task { let! o = fetchOrders ct in orders <- o })
 do! group.WaitAll()
val group: obj
val mutable user: obj
module Unchecked from Microsoft.FSharp.Core.Operators
val defaultof<'T> : 'T
val mutable orders: obj
val task: TaskBuilder

Constructors

Constructor Description

TaskGroup(parentToken)

Full Usage: TaskGroup(parentToken)

Parameters:
Returns: TaskGroup

Creates a TaskGroup linked to a parent CancellationToken. Parent token — group cancels when parent does.

parentToken : CancellationToken
Returns: TaskGroup

TaskGroup()

Full Usage: TaskGroup()

Returns: TaskGroup

Creates a TaskGroup with its own CancellationTokenSource.

Returns: TaskGroup

Instance members

Instance member Description

this.Run

Full Usage: this.Run

Parameters:

Add a task to the group. On failure, all other tasks are cancelled.

f : CancellationToken -> Task

Async function receiving the group's CancellationToken.

this.Token

Full Usage: this.Token

Returns: CancellationToken

Token that is cancelled when any task fails or the group is disposed.

Returns: CancellationToken

this.WaitAll

Full Usage: this.WaitAll

Returns: Task

Wait for all tasks to complete. Throws AggregateException if any failed.

Returns: Task

Type something to start searching.