Export (0) Print
Expand All

Async.Ignore<'T> Method (F#)

Creates an asynchronous computation that runs the given computation and ignores its result.

Namespace/Module Path: Microsoft.FSharp.Control

Assembly: FSharp.Core (in FSharp.Core.dll)

// Signature:
static member Ignore : Async<'T> -> Async<unit>

// Usage:
Async.Ignore (computation)

computation

Type: Async<'T>

The input computation.

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

The following code example illustrates the use of Async.Ignore.


open System
open System.IO

let writeToFile filename numBytes = 
    async {
        use file = File.Create(filename)
        printfn "Writing to file %s." filename
        do! file.AsyncWrite(Array.zeroCreate<byte> numBytes)
    }

let readFile filename numBytes =
    async {
        use file = File.OpenRead(filename)
        printfn "Reading from file %s." filename
        // Throw away the data being read.
        do! file.AsyncRead(numBytes) |> Async.Ignore
    }

let filename = "BigFile.dat"
let numBytes = 100000000

writeToFile filename numBytes
|> Async.RunSynchronously

readFile filename numBytes
|> Async.RunSynchronously


Windows 7, Windows Vista SP2, Windows XP SP3, Windows XP x64 SP2, Windows Server 2008 R2, Windows Server 2008 SP2, Windows Server 2003 SP2

F# Runtime

Supported in: 2.0, 4.0

Silverlight

Supported in: 3

Community Additions

ADD
Show:
© 2014 Microsoft