I am pleased to announce that there will be a C# 5.0 (*), and that in C# 5.0 you’ll be able to take this synchronous code:void ArchiveDocuments(Listurls)
{
for(int i = 0; i < urls.Count; ++i)
Archive(Fetch(urls[i]));
}and, given reasonable implementations of the FetchAsync and ArchiveAsync methods, transform it into this code to achieve the goal of sharing wait times as described yesterday:async void ArchiveDocuments(Listurls)
{
Task archive = null;
for(int i = 0; i < urls.Count; ++i)
{
var document = await FetchAsync(urls[i]);
if (archive != null)
await archive;
archive = ArchiveAsync(document);
}
}Where is the state machine code, the lambdas, the continuations, the checks to see if the task is already complete? They’re all still there. Let the compiler generate all that stuff for you
Thursday, October 28, 2010
C#: Async on the way!
Easy asynchronous communication, coming in C# 5:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment