可以编译以下代码.
async {
//do (
use outStream = File.Create(downloading)
do! httpRequestStreamCopyTo url outStream
//)
if File.Exists(fullname) then
File.Delete(fullname)
File.Move(downloading, fullname)
}
Run Code Online (Sandbox Code Playgroud)
我需要outStream在重命名之前关闭它.所以它改为
async {
do (
use outStream = File.Create(downloading)
do! httpRequestStreamCopyTo url outStream // Error
)
if File.Exists(fullname) then
File.Delete(fullname)
File.Move(downloading, fullname)
}
Run Code Online (Sandbox Code Playgroud)
它有以下错误do! httpRequestStreamCopyTo (reportingUri url) outStream?
错误FS0750此构造只能在计算表达式中使用
您可以等待这样的嵌入式async主体,以便outStream正确确定范围:
async {
do! async {
use outStream = File.Create(downloading)
do! httpRequestStreamCopyTo url outStream
}
if File.Exists(fullname) then
File.Delete(fullname)
File.Move(downloading, fullname)
}
Run Code Online (Sandbox Code Playgroud)
由于嵌入式主体是阻塞的,因此这在概念上等同于顺序async调用:
async {
use outStream = File.Create(downloading)
do! httpRequestStreamCopyTo url outStream
}
async {
if File.Exists(fullname) then
File.Delete(fullname)
File.Move(downloading, fullname)
}
Run Code Online (Sandbox Code Playgroud)