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,可移植