Holds static members for creating and manipulating asynchronous computations.
See also F# Language Guide - Async Workflows.
Static member | Description |
Full Usage:
Async.RunSynchronously(computation, ?timeout, ?cancellationToken)
Parameters:
Async<'T>
-
The computation to run.
?timeout : int
-
The amount of time in milliseconds to wait for the result of the
computation before raising a TimeoutException. If no value is provided
for timeout then a default of -1 is used to correspond to Timeout.Infinite.
?cancellationToken : CancellationToken
-
The cancellation token to be associated with the computation.
If one is not supplied, the default cancellation token is used.
Returns: 'T
The result of the computation.
|
If an exception occurs in the asynchronous computation then an exception is re-raised by this
function.
If no cancellation token is provided then the default cancellation token is used.
The computation is started on the current thread if SynchronizationContext.Current is null,
Thread.CurrentThread has Thread.IsThreadPoolThread
of
Example
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
val result: Async<unit>
val async: AsyncBuilder
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: seq<Async<'T option>> -> 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> static member Async.Sleep: dueTime: System.TimeSpan -> Async<unit>
static member Async.Sleep: millisecondsDueTime: int -> Async<unit> static member Async.RunSynchronously: computation: Async<'T> * ?timeout: int * ?cancellationToken: System.Threading.CancellationToken -> 'T
Prints "A", "B" immediately, then "C", "D" in 1 second. result is set to 17.
|
Full Usage:
Async.Start(computation, ?cancellationToken)
Parameters:
Async<unit>
-
The computation to run asynchronously.
?cancellationToken : CancellationToken
-
The cancellation token to be associated with the computation.
If one is not supplied, the default cancellation token is used.
|
If no cancellation token is provided then the default cancellation token is used.
Example
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
val async: AsyncBuilder
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: seq<Async<'T option>> -> 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> static member Async.Sleep: dueTime: System.TimeSpan -> Async<unit>
static member Async.Sleep: millisecondsDueTime: int -> Async<unit> static member Async.Start: computation: Async<unit> * ?cancellationToken: System.Threading.CancellationToken -> unit
Prints "A", then "D", "B" quickly in any order, and then "C" in 1 second.
|
Full Usage:
Async.StartAsTask(computation, ?taskCreationOptions, ?cancellationToken)
Parameters:
Async<'T>
?taskCreationOptions : TaskCreationOptions
?cancellationToken : CancellationToken
Returns: Task<'T>
A Task that will be completed
in the corresponding state once the computation terminates (produces the result, throws exception or gets canceled)
|
If no cancellation token is provided then the default cancellation token is used.
Example
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
val t: System.Threading.Tasks.Task<unit>
val async: AsyncBuilder
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: seq<Async<'T option>> -> 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> static member Async.Sleep: dueTime: System.TimeSpan -> Async<unit>
static member Async.Sleep: millisecondsDueTime: int -> Async<unit> static member Async.StartAsTask: computation: Async<'T> * ?taskCreationOptions: System.Threading.Tasks.TaskCreationOptions * ?cancellationToken: System.Threading.CancellationToken -> System.Threading.Tasks.Task<'T>
System.Threading.Tasks.Task.Wait() : unit
Prints "A", then "D", "B" quickly in any order, then "C", "E" in 1 second.
System.Threading.Tasks.Task.Wait(timeout: System.TimeSpan) : bool System.Threading.Tasks.Task.Wait(cancellationToken: System.Threading.CancellationToken) : unit System.Threading.Tasks.Task.Wait(millisecondsTimeout: int) : bool System.Threading.Tasks.Task.Wait(timeout: System.TimeSpan, cancellationToken: System.Threading.CancellationToken) : bool System.Threading.Tasks.Task.Wait(millisecondsTimeout: int, cancellationToken: System.Threading.CancellationToken) : bool |
Full Usage:
Async.StartChildAsTask(computation, ?taskCreationOptions)
Parameters:
Async<'T>
?taskCreationOptions : TaskCreationOptions
Returns: Async<Task<'T>>
|
|
Full Usage:
Async.StartImmediate(computation, ?cancellationToken)
Parameters:
Async<unit>
-
The asynchronous computation to execute.
?cancellationToken : CancellationToken
-
The CancellationToken to associate with the computation.
The default is used if this parameter is not provided.
|
If no cancellation token is provided then the default cancellation token is used.
Example
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
val async: AsyncBuilder
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: seq<Async<'T option>> -> 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> static member Async.Sleep: dueTime: System.TimeSpan -> Async<unit>
static member Async.Sleep: millisecondsDueTime: int -> Async<unit> static member Async.StartImmediate: computation: Async<unit> * ?cancellationToken: System.Threading.CancellationToken -> unit
Prints "A", "B", "D" immediately, then "C" in 1 second
|
Full Usage:
Async.StartImmediateAsTask(computation, ?cancellationToken)
Parameters:
Async<'T>
-
The asynchronous computation to execute.
?cancellationToken : CancellationToken
-
The CancellationToken to associate with the computation.
The default is used if this parameter is not provided.
Returns: Task<'T>
A Task that will be completed
in the corresponding state once the computation terminates (produces the result, throws exception or gets canceled)
|
![]() ![]() ![]() ![]() ![]() ![]() Runs an asynchronous computation, starting immediately on the current operating system thread, but also returns the execution as Task If no cancellation token is provided then the default cancellation token is used. You may prefer using this method if you want to achive a similar behviour to async await in C# as async computation starts on the current thread with an ability to return a result.
Example
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
val t: System.Threading.Tasks.Task<unit>
val async: AsyncBuilder
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: seq<Async<'T option>> -> 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> static member Async.Sleep: dueTime: System.TimeSpan -> Async<unit>
static member Async.Sleep: millisecondsDueTime: int -> Async<unit> static member Async.StartImmediateAsTask: computation: Async<'T> * ?cancellationToken: System.Threading.CancellationToken -> System.Threading.Tasks.Task<'T>
System.Threading.Tasks.Task.Wait() : unit
Prints "A", "B", "D" immediately, then "C", "E" in 1 second.
System.Threading.Tasks.Task.Wait(timeout: System.TimeSpan) : bool System.Threading.Tasks.Task.Wait(cancellationToken: System.Threading.CancellationToken) : unit System.Threading.Tasks.Task.Wait(millisecondsTimeout: int) : bool System.Threading.Tasks.Task.Wait(timeout: System.TimeSpan, cancellationToken: System.Threading.CancellationToken) : bool System.Threading.Tasks.Task.Wait(millisecondsTimeout: int, cancellationToken: System.Threading.CancellationToken) : bool |
Full Usage:
Async.StartWithContinuations(computation, continuation, exceptionContinuation, cancellationContinuation, ?cancellationToken)
Parameters:
Async<'T>
-
The asynchronous computation to execute.
continuation : 'T -> unit
-
The function called on success.
exceptionContinuation : exn -> unit
-
The function called on exception.
cancellationContinuation : OperationCanceledException -> unit
-
The function called on cancellation.
?cancellationToken : CancellationToken
-
The CancellationToken to associate with the computation.
The default is used if this parameter is not provided.
|
If no cancellation token is provided then the default cancellation token is used.
|
Static member | Description |
If any child computation raises an exception, then the overall computation will trigger an exception, and cancel the others. The overall computation will respond to cancellation while executing the child computations. If cancelled, the computation will cancel any remaining child computations but will still wait for the other child computations to complete. Example
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
val primes: int list
val computations: Async<int option> list
val i: int
val async: AsyncBuilder
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: seq<Async<'T option>> -> 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> static member Async.Sleep: dueTime: System.TimeSpan -> Async<unit>
static member Async.Sleep: millisecondsDueTime: int -> Async<unit> namespace System
Multiple items
type Random = new: unit -> unit + 1 overload member Next: unit -> int + 2 overloads member NextBytes: buffer: byte array -> unit + 1 overload member NextDouble: unit -> float member NextInt64: unit -> int64 + 2 overloads member NextSingle: unit -> float32 static member Shared: Random <summary>Represents a pseudo-random number generator, which is an algorithm that produces a sequence of numbers that meet certain statistical requirements for randomness.</summary> -------------------- System.Random() : System.Random System.Random(Seed: int) : System.Random union case Option.Some: Value: 'T -> Option<'T>
union case Option.None: Option<'T>
static member Async.Choice: computations: seq<Async<'T option>> -> Async<'T option>
static member Async.RunSynchronously: computation: Async<'T> * ?timeout: int * ?cancellationToken: System.Threading.CancellationToken -> 'T
Prints one randomly selected odd number in 1-2 seconds. If the list is changed to all even numbers, it will
instead print "No Result".
Example
val primes: int list
val computations: Async<int option> list
val i: int
val async: AsyncBuilder
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: seq<Async<'T option>> -> 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> static member Async.Sleep: dueTime: System.TimeSpan -> Async<unit>
static member Async.Sleep: millisecondsDueTime: int -> Async<unit> namespace System
Multiple items
type Random = new: unit -> unit + 1 overload member Next: unit -> int + 2 overloads member NextBytes: buffer: byte array -> unit + 1 overload member NextDouble: unit -> float member NextInt64: unit -> int64 + 2 overloads member NextSingle: unit -> float32 static member Shared: Random <summary>Represents a pseudo-random number generator, which is an algorithm that produces a sequence of numbers that meet certain statistical requirements for randomness.</summary> -------------------- System.Random() : System.Random System.Random(Seed: int) : System.Random union case Option.Some: Value: 'T -> Option<'T>
val failwith: message: string -> 'T
static member Async.Choice: computations: seq<Async<'T option>> -> Async<'T option>
static member Async.RunSynchronously: computation: Async<'T> * ?timeout: int * ?cancellationToken: System.Threading.CancellationToken -> 'T
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
union case Option.None: Option<'T>
Will sometimes print one randomly selected odd number, sometimes throw System.Exception("Even numbers not supported: 2").
|
|
Full Usage:
Async.FromContinuations(callback)
Parameters:
('T -> unit) * (exn -> unit) * (OperationCanceledException -> unit) -> unit
-
The function that accepts the current success, exception, and cancellation
continuations.
Returns: Async<'T>
An asynchronous computation that provides the callback with the current continuations.
|
Example
val someRiskyBusiness: unit -> unit
val dt: unit
val failwith: message: string -> 'T
val computation: Async<obj>
val successCont: (obj -> unit)
val exceptionCont: (exn -> unit)
val cancellationCont: (System.OperationCanceledException -> unit)
val oce: System.OperationCanceledException
val oce: exn
val e: exn
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: seq<Async<'T option>> -> 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> static member Async.FromContinuations: callback: (('T -> unit) * (exn -> unit) * (System.OperationCanceledException -> unit) -> unit) -> Async<'T>
static member Async.StartWithContinuations: computation: Async<'T> * continuation: ('T -> unit) * exceptionContinuation: (exn -> unit) * cancellationContinuation: (System.OperationCanceledException -> unit) * ?cancellationToken: System.Threading.CancellationToken -> unit
val result: obj
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
This anonymous function will call someRiskyBusiness() and properly use the provided continuations
defined to report the outcome.
|
|
Example
val readFile: filename: string -> numBytes: int -> Async<unit>
val filename: string
val numBytes: int
val async: AsyncBuilder
val file: System.IO.FileStream
namespace System
namespace System.IO
type File =
static member AppendAllLines: path: string * contents: IEnumerable<string> -> unit + 1 overload
static member AppendAllLinesAsync: path: string * contents: IEnumerable<string> * encoding: Encoding * ?cancellationToken: CancellationToken -> Task + 1 overload
static member AppendAllText: path: string * contents: string -> unit + 1 overload
static member AppendAllTextAsync: path: string * contents: string * encoding: Encoding * ?cancellationToken: CancellationToken -> Task + 1 overload
static member AppendText: path: string -> StreamWriter
static member Copy: sourceFileName: string * destFileName: string -> unit + 1 overload
static member Create: path: string -> FileStream + 2 overloads
static member CreateSymbolicLink: path: string * pathToTarget: string -> FileSystemInfo
static member CreateText: path: string -> StreamWriter
static member Decrypt: path: string -> unit
...
<summary>Provides static methods for the creation, copying, deletion, moving, and opening of a single file, and aids in the creation of <see cref="T:System.IO.FileStream" /> objects.</summary> System.IO.File.OpenRead(path: string) : System.IO.FileStream
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
member System.IO.Stream.AsyncRead: count: int -> Async<byte array>
member System.IO.Stream.AsyncRead: buffer: byte array * ?offset: int * ?count: int -> Async<int> 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: seq<Async<'T option>> -> 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> static member Async.Ignore: computation: Async<'T> -> Async<unit>
static member Async.Start: computation: Async<unit> * ?cancellationToken: System.Threading.CancellationToken -> unit
Reads bytes from a given file asynchronously and then ignores the result, allowing the do! to be used with functions
that return an unwanted value.
|
Full Usage:
Async.Parallel(computations, ?maxDegreeOfParallelism)
Parameters:
seq<Async<'T>>
-
A sequence of distinct computations to be parallelized.
?maxDegreeOfParallelism : int
-
The maximum degree of parallelism in the parallel execution.
Returns: Async<'T[]>
A computation that returns an array of values from the sequence of input computations.
|
If all child computations succeed, an array of results is passed to the success continuation. If any child computation raises an exception, then the overall computation will trigger an exception, and cancel the others. The overall computation will respond to cancellation while executing the child computations. If cancelled, the computation will cancel any remaining child computations but will still wait for the other child computations to complete.
Example
val primes: int list
val computations: Async<bool> list
val i: int
val async: AsyncBuilder
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: seq<Async<'T option>> -> 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> static member Async.Sleep: dueTime: System.TimeSpan -> Async<unit>
static member Async.Sleep: millisecondsDueTime: int -> Async<unit> namespace System
Multiple items
type Random = new: unit -> unit + 1 overload member Next: unit -> int + 2 overloads member NextBytes: buffer: byte array -> unit + 1 overload member NextDouble: unit -> float member NextInt64: unit -> int64 + 2 overloads member NextSingle: unit -> float32 static member Shared: Random <summary>Represents a pseudo-random number generator, which is an algorithm that produces a sequence of numbers that meet certain statistical requirements for randomness.</summary> -------------------- System.Random() : System.Random System.Random(Seed: int) : System.Random val printfn: format: Printf.TextWriterFormat<'T> -> 'T
val t: System.Threading.Tasks.Task<bool array>
static member Async.Parallel: computations: seq<Async<'T>> -> Async<'T array>
static member Async.Parallel: computations: seq<Async<'T>> * ?maxDegreeOfParallelism: int -> Async<'T array> static member Async.StartAsTask: computation: Async<'T> * ?taskCreationOptions: System.Threading.Tasks.TaskCreationOptions * ?cancellationToken: System.Threading.CancellationToken -> System.Threading.Tasks.Task<'T>
System.Threading.Tasks.Task.Wait() : unit
System.Threading.Tasks.Task.Wait(timeout: System.TimeSpan) : bool System.Threading.Tasks.Task.Wait(cancellationToken: System.Threading.CancellationToken) : unit System.Threading.Tasks.Task.Wait(millisecondsTimeout: int) : bool System.Threading.Tasks.Task.Wait(timeout: System.TimeSpan, cancellationToken: System.Threading.CancellationToken) : bool System.Threading.Tasks.Task.Wait(millisecondsTimeout: int, cancellationToken: System.Threading.CancellationToken) : bool property System.Threading.Tasks.Task.Result: bool array with get
This will print "3", "5" (in any order) in 1-2 seconds, and then "7", "11" (in any order) in 1-2 more seconds and then
[| false; true; true; true; false; true |].
|
|
If all child computations succeed, an array of results is passed to the success continuation. If any child computation raises an exception, then the overall computation will trigger an exception, and cancel the others. The overall computation will respond to cancellation while executing the child computations. If cancelled, the computation will cancel any remaining child computations but will still wait for the other child computations to complete.
Example
val primes: int list
val t: System.Threading.Tasks.Task<bool array>
val i: int
val async: AsyncBuilder
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: seq<Async<'T option>> -> 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> static member Async.Sleep: dueTime: System.TimeSpan -> Async<unit>
static member Async.Sleep: millisecondsDueTime: int -> Async<unit> namespace System
Multiple items
type Random = new: unit -> unit + 1 overload member Next: unit -> int + 2 overloads member NextBytes: buffer: byte array -> unit + 1 overload member NextDouble: unit -> float member NextInt64: unit -> int64 + 2 overloads member NextSingle: unit -> float32 static member Shared: Random <summary>Represents a pseudo-random number generator, which is an algorithm that produces a sequence of numbers that meet certain statistical requirements for randomness.</summary> -------------------- System.Random() : System.Random System.Random(Seed: int) : System.Random val printfn: format: Printf.TextWriterFormat<'T> -> 'T
static member Async.Parallel: computations: seq<Async<'T>> -> Async<'T array>
static member Async.Parallel: computations: seq<Async<'T>> * ?maxDegreeOfParallelism: int -> Async<'T array> static member Async.StartAsTask: computation: Async<'T> * ?taskCreationOptions: System.Threading.Tasks.TaskCreationOptions * ?cancellationToken: System.Threading.CancellationToken -> System.Threading.Tasks.Task<'T>
System.Threading.Tasks.Task.Wait() : unit
System.Threading.Tasks.Task.Wait(timeout: System.TimeSpan) : bool System.Threading.Tasks.Task.Wait(cancellationToken: System.Threading.CancellationToken) : unit System.Threading.Tasks.Task.Wait(millisecondsTimeout: int) : bool System.Threading.Tasks.Task.Wait(timeout: System.TimeSpan, cancellationToken: System.Threading.CancellationToken) : bool System.Threading.Tasks.Task.Wait(millisecondsTimeout: int, cancellationToken: System.Threading.CancellationToken) : bool property System.Threading.Tasks.Task.Result: bool array with get
This will print "3", "5", "7", "11" (in any order) in 1-2 seconds and then [| false; true; true; true; false; true |].
|
|
If all child computations succeed, an array of results is passed to the success continuation. If any child computation raises an exception, then the overall computation will trigger an exception, and cancel the others. The overall computation will respond to cancellation while executing the child computations. If cancelled, the computation will cancel any remaining child computations but will still wait for the other child computations to complete.
Example
val primes: int list
val computations: Async<bool> list
val i: int
val async: AsyncBuilder
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: seq<Async<'T option>> -> 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> static member Async.Sleep: dueTime: System.TimeSpan -> Async<unit>
static member Async.Sleep: millisecondsDueTime: int -> Async<unit> namespace System
Multiple items
type Random = new: unit -> unit + 1 overload member Next: unit -> int + 2 overloads member NextBytes: buffer: byte array -> unit + 1 overload member NextDouble: unit -> float member NextInt64: unit -> int64 + 2 overloads member NextSingle: unit -> float32 static member Shared: Random <summary>Represents a pseudo-random number generator, which is an algorithm that produces a sequence of numbers that meet certain statistical requirements for randomness.</summary> -------------------- System.Random() : System.Random System.Random(Seed: int) : System.Random val printfn: format: Printf.TextWriterFormat<'T> -> 'T
val t: System.Threading.Tasks.Task<bool array>
static member Async.Sequential: computations: seq<Async<'T>> -> Async<'T array>
static member Async.StartAsTask: computation: Async<'T> * ?taskCreationOptions: System.Threading.Tasks.TaskCreationOptions * ?cancellationToken: System.Threading.CancellationToken -> System.Threading.Tasks.Task<'T>
System.Threading.Tasks.Task.Wait() : unit
System.Threading.Tasks.Task.Wait(timeout: System.TimeSpan) : bool System.Threading.Tasks.Task.Wait(cancellationToken: System.Threading.CancellationToken) : unit System.Threading.Tasks.Task.Wait(millisecondsTimeout: int) : bool System.Threading.Tasks.Task.Wait(timeout: System.TimeSpan, cancellationToken: System.Threading.CancellationToken) : bool System.Threading.Tasks.Task.Wait(millisecondsTimeout: int, cancellationToken: System.Threading.CancellationToken) : bool property System.Threading.Tasks.Task.Result: bool array with get
This will print "3", "5", "7", "11" with ~1-2 seconds between them except for pauses where even numbers would be and then
prints [| false; true; true; true; false; true |].
|
Static member | Description | ||
Full Usage:
Async.AwaitEvent(event, ?cancelAction)
Parameters:
IEvent<'Del, 'T>
-
The event to handle once.
?cancelAction : unit -> unit
-
An optional function to execute instead of cancelling when a
cancellation is issued.
Returns: Async<'T>
An asynchronous computation that waits for the event to be invoked.
|
The computation will respond to cancellation while waiting for the event. If a
cancellation occurs, and
|
||
Full Usage:
Async.AwaitIAsyncResult(iar, ?millisecondsTimeout)
Parameters:
IAsyncResult
-
The IAsyncResult to wait on.
?millisecondsTimeout : int
-
The timeout value in milliseconds. If one is not provided
then the default value of -1 corresponding to Timeout.Infinite.
Returns: Async<bool>
An asynchronous computation that waits on the given IAsyncResult .
|
The computation returns true if the handle indicated a result within the given timeout.
|
||
|
If an exception occurs in the asynchronous computation then an exception is re-raised by this
function.
If the task is cancelled then Tasks.TaskCanceledException is raised. Note
that the task may be governed by a different cancellation token to the overall async computation
where the AwaitTask occurs. In practice you should normally start the task with the
cancellation token returned by
|
||
|
If an exception occurs in the asynchronous computation then an exception is re-raised by this
function.
If the task is cancelled then Tasks.TaskCanceledException is raised. Note
that the task may be governed by a different cancellation token to the overall async computation
where the AwaitTask occurs. In practice you should normally start the task with the
cancellation token returned by
|
||
Full Usage:
Async.AwaitWaitHandle(waitHandle, ?millisecondsTimeout)
Parameters:
WaitHandle
-
The WaitHandle that can be signalled.
?millisecondsTimeout : int
-
The timeout value in milliseconds. If one is not provided
then the default value of -1 corresponding to Timeout.Infinite.
Returns: Async<bool>
An asynchronous computation that waits on the given WaitHandle .
|
The computation returns true if the handle indicated a result within the given timeout.
|
||
|
Example
val async: AsyncBuilder
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
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: seq<Async<'T option>> -> 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> static member Async.Sleep: dueTime: System.TimeSpan -> Async<unit>
static member Async.Sleep: millisecondsDueTime: int -> Async<unit> static member Async.Start: computation: Async<unit> * ?cancellationToken: System.Threading.CancellationToken -> unit
Prints "C", then "A" quickly, and then "B" 1 second later.
|
||
|
Example
val async: AsyncBuilder
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
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: seq<Async<'T option>> -> 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> static member Async.Sleep: dueTime: System.TimeSpan -> Async<unit>
static member Async.Sleep: millisecondsDueTime: int -> Async<unit> static member Async.Start: computation: Async<unit> * ?cancellationToken: System.Threading.CancellationToken -> unit
Prints "C", then "A" quickly, and then "B" 1 second later
|
Static member | Description |
Full Usage:
Async.CancelDefaultToken()
|
![]() ![]() ![]() ![]() ![]() ![]() Raises the cancellation condition for the most recent set of asynchronous computations started without any specific CancellationToken. Replaces the global CancellationTokenSource with a new global token source for any asynchronous computations created after this point without any specific CancellationToken. Example
val primes: int list
val computations: Async<unit> list
val i: int
val async: AsyncBuilder
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: seq<Async<'T option>> -> 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> static member Async.Sleep: dueTime: System.TimeSpan -> Async<unit>
static member Async.Sleep: millisecondsDueTime: int -> Async<unit> val printfn: format: Printf.TextWriterFormat<'T> -> 'T
val t: System.Threading.Tasks.Task<unit array>
static member Async.Parallel: computations: seq<Async<'T>> -> Async<'T array>
static member Async.Parallel: computations: seq<Async<'T>> * ?maxDegreeOfParallelism: int -> Async<'T array> static member Async.StartAsTask: computation: Async<'T> * ?taskCreationOptions: System.Threading.Tasks.TaskCreationOptions * ?cancellationToken: System.Threading.CancellationToken -> System.Threading.Tasks.Task<'T>
static member Async.CancelDefaultToken: unit -> unit
property System.Threading.Tasks.Task.Result: unit array with get
namespace System
Multiple items
type AggregateException = inherit exn new: unit -> unit + 6 overloads member Flatten: unit -> AggregateException member GetBaseException: unit -> exn member GetObjectData: info: SerializationInfo * context: StreamingContext -> unit member Handle: predicate: Func<exn,bool> -> unit member ToString: unit -> string member InnerExceptions: ReadOnlyCollection<exn> member Message: string <summary>Represents one or more errors that occur during application execution.</summary> -------------------- System.AggregateException() : System.AggregateException System.AggregateException(innerExceptions: System.Collections.Generic.IEnumerable<exn>) : System.AggregateException System.AggregateException([<System.ParamArray>] innerExceptions: exn array) : System.AggregateException System.AggregateException(message: string) : System.AggregateException System.AggregateException(message: string, innerExceptions: System.Collections.Generic.IEnumerable<exn>) : System.AggregateException System.AggregateException(message: string, innerException: exn) : System.AggregateException System.AggregateException(message: string, [<System.ParamArray>] innerExceptions: exn array) : System.AggregateException val ae: System.AggregateException
property System.AggregateException.Message: string with get
This will print "2" 2 seconds from start, "3" 3 seconds from start, "5" 5 seconds from start, cease computation and
then print "Tasks Not Finished: One or more errors occurred. (A task was canceled.)".
<summary>Gets a message that describes the exception.</summary> <returns>The message that describes the exception.</returns> |
Full Usage:
Async.CancellationToken
Returns: Async<CancellationToken>
An asynchronous computation capable of retrieving the CancellationToken from a computation
expression.
|
In
|
|
Example
val someRiskyBusiness: unit -> unit
val dt: unit
val failwith: message: string -> 'T
val async: AsyncBuilder
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: seq<Async<'T option>> -> 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> static member Async.Catch: computation: Async<'T> -> Async<Choice<'T,exn>>
static member Async.RunSynchronously: computation: Async<'T> * ?timeout: int * ?cancellationToken: System.Threading.CancellationToken -> 'T
union case Choice.Choice1Of2: 'T1 -> Choice<'T1,'T2>
val result: obj
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
union case Choice.Choice2Of2: 'T2 -> Choice<'T1,'T2>
val e: exn
Prints the returned value of someRiskyBusiness() or the exception if there is one.
|
Full Usage:
Async.DefaultCancellationToken
Returns: CancellationToken
The default CancellationToken.
|
Example
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: seq<Async<'T option>> -> 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> property Async.DefaultCancellationToken: System.Threading.CancellationToken with get
System.Threading.CancellationToken.Register(callback: System.Action) : System.Threading.CancellationTokenRegistration
System.Threading.CancellationToken.Register(callback: System.Action<obj>, state: obj) : System.Threading.CancellationTokenRegistration System.Threading.CancellationToken.Register(callback: System.Action<obj,System.Threading.CancellationToken>, state: obj) : System.Threading.CancellationTokenRegistration System.Threading.CancellationToken.Register(callback: System.Action, useSynchronizationContext: bool) : System.Threading.CancellationTokenRegistration System.Threading.CancellationToken.Register(callback: System.Action<obj>, state: obj, useSynchronizationContext: bool) : System.Threading.CancellationTokenRegistration val printfn: format: Printf.TextWriterFormat<'T> -> 'T
val ignore: value: 'T -> unit
val primes: int list
val i: int
val async: AsyncBuilder
static member Async.Sleep: dueTime: System.TimeSpan -> Async<unit>
static member Async.Sleep: millisecondsDueTime: int -> Async<unit> static member Async.Start: computation: Async<unit> * ?cancellationToken: System.Threading.CancellationToken -> unit
static member Async.CancelDefaultToken: unit -> unit
This will print "2" 2 seconds from start, "3" 3 seconds from start, "5" 5 seconds from start, cease computation and then
print "Computation Cancelled", followed by "Tasks Finished".
|
Full Usage:
Async.OnCancel(interruption)
Parameters:
unit -> unit
-
The function that is executed on the thread performing the
cancellation.
Returns: Async<IDisposable>
An asynchronous computation that triggers the interruption if it is cancelled
before being disposed.
|
For example,
Example
val primes: int list
val i: int
val async: AsyncBuilder
val holder: System.IDisposable
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: seq<Async<'T option>> -> 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> static member Async.OnCancel: interruption: (unit -> unit) -> Async<System.IDisposable>
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
static member Async.Sleep: dueTime: System.TimeSpan -> Async<unit>
static member Async.Sleep: millisecondsDueTime: int -> Async<unit> static member Async.Start: computation: Async<unit> * ?cancellationToken: System.Threading.CancellationToken -> unit
static member Async.CancelDefaultToken: unit -> unit
This will print "2" 2 seconds from start, "3" 3 seconds from start, "5" 5 seconds from start, cease computation
and then print "Computation Cancelled: 7", "Computation Cancelled: 11" and "Tasks Finished" in any order.
|
Full Usage:
Async.StartChild(computation, ?millisecondsTimeout)
Parameters:
Async<'T>
-
The child computation.
?millisecondsTimeout : int
-
The timeout value in milliseconds. If one is not provided
then the default value of -1 corresponding to Timeout.Infinite.
Returns: Async<Async<'T>>
A new computation that waits for the input computation to finish.
|
This method should normally be used as the immediate
right-hand-side of a
val async: AsyncBuilder
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: seq<Async<'T option>> -> 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> static member Async.StartChild: computation: Async<'T> * ?millisecondsTimeout: int -> Async<Async<'T>>
When used in this way, each use of StartChild starts an instance of childComputation
and returns a completor object representing a computation to wait for the completion of the operation.
When executed, the completor awaits the completion of childComputation .
Example
val computeWithTimeout: timeout: int -> unit
val timeout: int
val async: AsyncBuilder
val completor1: Async<int>
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: seq<Async<'T option>> -> 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> static member Async.StartChild: computation: Async<'T> * ?millisecondsTimeout: int -> Async<Async<'T>>
static member Async.Sleep: dueTime: System.TimeSpan -> Async<unit>
static member Async.Sleep: millisecondsDueTime: int -> Async<unit> val completor2: Async<int>
val v1: int
val v2: int
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
static member Async.RunSynchronously: computation: Async<'T> * ?timeout: int * ?cancellationToken: System.Threading.CancellationToken -> 'T
Will throw a System.TimeoutException if called with a timeout less than 2000, otherwise will print "Result: 3".
|
Full Usage:
Async.TryCancelled(computation, compensation)
Parameters:
Async<'T>
-
The input asynchronous computation.
compensation : OperationCanceledException -> unit
-
The function to be run if the computation is cancelled.
Returns: Async<'T>
An asynchronous computation that runs the compensation if the input computation
is cancelled.
|
Example
val primes: int list
val i: int
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: seq<Async<'T option>> -> 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> static member Async.TryCancelled: computation: Async<'T> * compensation: (System.OperationCanceledException -> unit) -> Async<'T>
val async: AsyncBuilder
static member Async.Sleep: dueTime: System.TimeSpan -> Async<unit>
static member Async.Sleep: millisecondsDueTime: int -> Async<unit> val printfn: format: Printf.TextWriterFormat<'T> -> 'T
val oce: System.OperationCanceledException
static member Async.Start: computation: Async<unit> * ?cancellationToken: System.Threading.CancellationToken -> unit
static member Async.CancelDefaultToken: unit -> unit
This will print "2" 2 seconds from start, "3" 3 seconds from start, "5" 5 seconds from start, cease computation
and then print "Computation Cancelled: 7", "Computation Cancelled: 11" and "Tasks Finished" in any order.
|
Static member | Description |
Full Usage:
Async.SwitchToContext(syncContext)
Parameters:
SynchronizationContext
-
The synchronization context to accept the posted computation.
Returns: Async<unit>
An asynchronous computation that uses the syncContext context to execute.
|
|
|
Example
val async: AsyncBuilder
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: seq<Async<'T option>> -> 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> static member Async.SwitchToNewThread: unit -> Async<unit>
static member Async.StartImmediate: computation: Async<unit> * ?cancellationToken: System.Threading.CancellationToken -> unit
This will run someLongRunningComputation() without blocking the threads in the threadpool.
|
|
Example
val async: AsyncBuilder
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: seq<Async<'T option>> -> 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> static member Async.SwitchToNewThread: unit -> Async<unit>
static member Async.SwitchToThreadPool: unit -> Async<unit>
val i: int
static member Async.StartImmediate: computation: Async<unit> * ?cancellationToken: System.Threading.CancellationToken -> unit
This will run someLongRunningComputation() without blocking the threads in the threadpool, and then switch to the
threadpool for shorter computations.
|
Static member | Description |
Full Usage:
Async.AsBeginEnd(computation)
Parameters:
'Arg -> Async<'T>
-
A function generating the asynchronous computation to split into the traditional
.NET Asynchronous Programming Model.
Returns: ('Arg * AsyncCallback * obj -> IAsyncResult) * (IAsyncResult -> 'T) * (IAsyncResult -> unit)
A tuple of the begin, end, and cancel members.
|
|
Full Usage:
Async.FromBeginEnd(arg1, arg2, arg3, beginAction, endAction, ?cancelAction)
Parameters:
'Arg1
-
The first argument for the operation.
arg2 : 'Arg2
-
The second argument for the operation.
arg3 : 'Arg3
-
The third argument for the operation.
beginAction : 'Arg1 * 'Arg2 * 'Arg3 * AsyncCallback * obj -> IAsyncResult
-
The function initiating a traditional CLI asynchronous operation.
endAction : IAsyncResult -> 'T
-
The function completing a traditional CLI asynchronous operation.
?cancelAction : unit -> unit
-
An optional function to be executed when a cancellation is requested.
Returns: Async<'T>
An asynchronous computation wrapping the given Begin/End functions.
|
The computation will respond to cancellation while waiting for the completion
of the operation. If a cancellation occurs, and
|
Full Usage:
Async.FromBeginEnd(arg1, arg2, beginAction, endAction, ?cancelAction)
Parameters:
'Arg1
-
The first argument for the operation.
arg2 : 'Arg2
-
The second argument for the operation.
beginAction : 'Arg1 * 'Arg2 * AsyncCallback * obj -> IAsyncResult
-
The function initiating a traditional CLI asynchronous operation.
endAction : IAsyncResult -> 'T
-
The function completing a traditional CLI asynchronous operation.
?cancelAction : unit -> unit
-
An optional function to be executed when a cancellation is requested.
Returns: Async<'T>
An asynchronous computation wrapping the given Begin/End functions.
|
The computation will respond to cancellation while waiting for the completion
of the operation. If a cancellation occurs, and
|
Full Usage:
Async.FromBeginEnd(arg, beginAction, endAction, ?cancelAction)
Parameters:
'Arg1
-
The argument for the operation.
beginAction : 'Arg1 * AsyncCallback * obj -> IAsyncResult
-
The function initiating a traditional CLI asynchronous operation.
endAction : IAsyncResult -> 'T
-
The function completing a traditional CLI asynchronous operation.
?cancelAction : unit -> unit
-
An optional function to be executed when a cancellation is requested.
Returns: Async<'T>
An asynchronous computation wrapping the given Begin/End functions.
|
The computation will respond to cancellation while waiting for the completion
of the operation. If a cancellation occurs, and
|
Full Usage:
Async.FromBeginEnd(beginAction, endAction, ?cancelAction)
Parameters:
AsyncCallback * obj -> IAsyncResult
-
The function initiating a traditional CLI asynchronous operation.
endAction : IAsyncResult -> 'T
-
The function completing a traditional CLI asynchronous operation.
?cancelAction : unit -> unit
-
An optional function to be executed when a cancellation is requested.
Returns: Async<'T>
An asynchronous computation wrapping the given Begin/End functions.
|
The computation will respond to cancellation while waiting for the completion
of the operation. If a cancellation occurs, and
|