参数顺序和右管道运算符
有没有办法简化以下操作,这样我就不需要 runWithTimeout 函数?
let runWithTimeout timeout computation =
Async.RunSynchronously(computation, timeout)
let processOneItem item = fetchAction item
|> runWithTimeout 2000
编辑: 这就是我需要额外方法的原因:
let processOneItem item = fetchAction item
|> Async.Catch
|> runWithTimeout 2000
|> handleExceptions
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许你的意思是这样的:
Perhaps you mean something like this:
我不太热衷于使用 fun x -> ... 作为管道的一部分。
我认为,当 API(例如列表)支持时,编写代码的流水线风格很好,但是当 API 不适合这种风格时,最好遵循通常的“类 C#”风格。当然,这只是个人喜好,但我只想写:
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 (e.g. 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:
这是一个更完整的示例,以供将来参考:
Here's a more complete sample, for future reference: