我有一个 F# 函数,如下所示:
open System.IO
open Microsoft.FSharp.Control.CommonExtensions
let rec copyData (ins:Stream) (outs:Stream) = async {
let! bytes = ins.AsyncRead(1)
do! outs.AsyncWrite(bytes)
return! moveData ins outs
}
当ins
流到达末尾时,它会引发AtEndOfStream
异常。所以我必须在调用函数中捕获它。如何通过检测流当前处于末尾来防止此异常?