参考老赵文章里的代码:
写了一个简单的代码,异步的在两个流之间搬运数据。这里一个是打开的文件流,另一个是 Console 输出流:
open System.IO
let rec transferAsync (inStream: Stream) (outStream: Stream) buffer =
async {
let! lengthRead = inStream.AsyncRead(buffer, 0, buffer.Length)
if lengthRead > 0 then
do! outStream.AsyncWrite(buffer, 0, lengthRead)
do! transferAsync inStream outStream buffer
}
let buf = Array.zeroCreate 1024
let fs = File.OpenRead("E:\SQL游标代码模板.sql")
let outs = System.Console.OpenStandardOutput()
transferAsync fs outs buf
|> Async.RunSynchronously
printfn "complete."
System.Console.ReadLine() |> ignore
over.