Async.Ignore<'T> 方法 (F#)
建立會執行所指定計算並忽略其結果的非同步計算。
**命名空間/模組路徑:**Microsoft.FSharp.Control
組件:FSharp.Core (在 FSharp.Core.dll 中)
// Signature:
static member Ignore : Async<'T> -> Async<unit>
// Usage:
Async.Ignore (computation)
參數
computation
型別:Async<'T>輸入計算。
傳回值
相當於輸入計算但會忽略結果的計算。
範例
下列程式碼範例說明如何使用 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# 核心程式庫版本
支援版本:2.0, 4.0,可攜式執行檔 (PE)。