【发布时间】:2019-08-05 06:17:36
【问题描述】:
假设我们有一个提供高阶函数applyTest的库。
这可以与异步函数asyncFunction 一起使用,同时保留异步代码的好处吗?
是否可以将库设计为更好地支持异步应用程序而无需专门提供异步版本?
let applyTest f =
f 2 > 0
let syncFunction x =
x - 1
let asyncFunction x =
x - 2 |> async.Return
async {
let a = applyTest syncFunction
let b = applyTest (asyncFunction >> Async.RunSynchronously)
printfn "a = %b, b = %b" a b
}
|> Async.RunSynchronously
【问题讨论】:
标签: asynchronous f# higher-order-functions