异步 CTP 和超时
我开始观看 Jon Skeet 关于 C# Async CTP 的演示。当谈到指定暂停时,他结结巴巴。
由于对 F# 的了解相当有限,因此有一种直观、集中且简单的方法来指定超时。所以,我想知道目前的情况是什么:C# Async CTP 可以完成 F# async block runner 所做的所有事情吗?是否有一份文件概述了差异和限制?
其他详细信息: 在 F# 中,异步块运行程序提供了一种指定以下内容的方法:
- 异常流
- 超时流
- 取消流
- 对上述三个功能的可扩展性
以下是在 F# 中执行这些操作的方法: 参数顺序和管道右运算符
I started watching Jon Skeet's presentation on C# Async CTP. He stuttered when it came to specifying timeouts.
Coming from fairly limited exposure to F#, there is an intuitive, centralized, and simple way to specify timeouts. So, I am wondering what is the current state of affairs: can C# Async CTP do all the things that F# async block runner does? Is there a document that outlines differences and limitations?
Additional details:
In F#, the async block runner provides a way to specify the following:
- Exception flow
- Timeout flow
- Cancellation flow
- Extensibility to the above three features
Here's a way to do these things in F#:
Order of arguments and pipe-right operator
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我什至不记得提到过超时 - 但我会相信你的话:)
编写任务来实现超时相当容易:创建第二个任务,这是一个“延迟”,然后等待该任务或原来要完成的任务。无论哪一个先到达,如果可行的话(使用取消令牌)取消另一个。新创建的任务将完成主操作的结果(如果成功),或者如果“延迟”首先完成则出现异常。
我没有看到 AsyncCtpLibrary.dll 中直接支持的类似内容,但您可以使用提供的工具轻松地构建它。您可能需要查看“基于任务的异步模式概述”和“< a href="http://go.microsoft.com/fwlink/?LinkId=205053" rel="nofollow">TPL Dataflow" 文档,看看它们是否也涵盖了它。
I don't even remember mentioning timeouts - but I'll take your word for it :)
It's fairly easy to compose tasks to achieve a timeout: create a second task which is a "delay", and then wait for either that or the original task to complete. Whichever one gets there first, cancel the other if feasible (with a cancellation token). The newly created task will complete with either the result of the main operation (if that succeeded) or an exception if the "delay" finished first.
I don't see anything like that directly supported in AsyncCtpLibrary.dll, but you can build it reasonably easily from the tools which are provided. You may want to look in the "Task-Based Asynchronous Pattern Overview" and "TPL Dataflow" documents to see if they cover it, too.