Order of arguments and pipe
Is there a way to simplify the following, so I won't need a runWithTimeout function?
let runWithTimeout timeout computation =
Async.RunSynchronously(computation, timeout)
let processOneItem item = fetchAction item
|> runWithTimeout 2000
Edit: Here's why i needed the extra method:
let processOneItem item = fetchAction item
|> Async.Catch
|> runWithTimeout 2000
|> handleExceptions
也许你的意思是这样的:
let processOneItem item =
fetchAction item
|> fun x -> Async.RunSynchronously(x, 2000)
I'm not very keen on using fun x -> ...
as part of a pipeline.
I think that the pipelining style of writing code is nice when it is supported by the API (eg lists), but when the API doesn't fit the style, it is just better to follow the usual "C#-like" style. Of coures, this is just a personal preference, but I'd just write:
let processOneItem item =
let work = Async.Catch(fetchAction item)
let result = Async.RunSynchronously(work, 30000)
handleExceptions result
这是一个更完整的示例,供将来参考:
let processOneItem item = fetchAction item
|> Async.Catch
|> fun x -> Async.RunSynchronously(x,30000)
|> handleExceptions
链接地址: http://www.djcxy.com/p/39516.html
上一篇: 如何在Java中为Android设置HttpResponse超时
下一篇: 参数和管道的顺序