简体   繁体   English

异步 CTP 和超时

[英]Async CTP and timeouts

I started watching Jon Skeet's presentation on C# Async CTP .我开始观看Jon Skeet 关于 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.由于对 F# 的接触相当有限,因此有一种直观、集中且简单的方法来指定超时。 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?所以,我想知道当前的 state 事务是什么:C# Async CTP 可以做 F# async block runner 做的所有事情吗? Is there a document that outlines differences and limitations?是否有概述差异和限制的文件?


Additional details: In F#, the async block runner provides a way to specify the following:其他详细信息:在 F# 中,异步块运行器提供了一种指定以下内容的方法:

  1. Exception flow异常流
  2. Timeout flow超时流程
  3. Cancellation flow取消流程
  4. Extensibility to the above three features上述三个特性的可扩展性

Here's a way to do these things in F#: Order of arguments and pipe-right operator这是在 F# 中执行这些操作的方法: arguments 和管道权限运算符的顺序

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.我没有看到AsyncCtpLibrary.dll 直接支持类似的东西,但是您可以使用提供的工具相当容易地构建它。 You may want to look in the " Task-Based Asynchronous Pattern Overview " and " TPL Dataflow " documents to see if they cover it, too.您可能想查看“基于任务的异步模式概述”和“ TPL 数据流”文档,看看它们是否也涵盖了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM