Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Async CTP and timeouts

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:

  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

like image 622
GregC Avatar asked May 05 '11 05:05

GregC


1 Answers

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.

like image 119
Jon Skeet Avatar answered Sep 30 '22 05:09

Jon Skeet