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)

Parameters

  • computation
    Type: Async<'T>

    The input computation.

Return Value

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

Example

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

Platforms

Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2

Version Information

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

See Also

Reference

Control.Async Class (F#)

Microsoft.FSharp.Control Namespace (F#)