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 8, Windows 7, Windows Server 2012, Windows Server 2008 R2

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft