可以编译以下代码。
async {
//do (
use outStream = File.Create(downloading)
do! httpRequestStreamCopyTo url outStream
//)
if File.Exists(fullname) then
File.Delete(fullname)
File.Move(downloading, fullname)
}
我需要在重命名前关闭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)
}
它在do! httpRequestStreamCopyTo (reportingUri url) outStream
上出现以下错误?
错误FS0750此构造只能在计算表达式中使用
答案 0 :(得分:6)
您可以等待嵌入式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)
}
由于嵌入式主体是阻塞的,因此这在概念上等同于顺序async
调用:
async {
use outStream = File.Create(downloading)
do! httpRequestStreamCopyTo url outStream
}
async {
if File.Exists(fullname) then
File.Delete(fullname)
File.Move(downloading, fullname)
}