The new C# 5.0 proposes to bring asynchronous keywords, which I believe works like macros to turn imperative code into continuations.
The “await” operator used twice in
that method does not mean “this method now blocks
the current thread until the asynchronous
operation returns”. That would be making
the asynchronous operation back into a
synchronous operation, which is precisely
what we are attempting to avoid. Rather,
it means the opposite of that; it means
“if the task we are awaiting has
not yet completed then sign up the rest of
this method as the continuation of that task,
and then return to your caller immediately;
the task will invoke the continuation when
it completes.”
async void ArchiveDocuments(List<Url> urls)
{
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);
}
}
Microsoft has been very lucky to have someone like Anders Hejlsberg, who has steadily brought a stream of features to an enterprise programming language.
Yes, what is true is the fact, that they are finally working on a better ways to support async-code in a more frictionless way... (yes, Hejlsberg, F# team and Async Team rock, as does Erik Maijer)
They are still not where they would like to be though i guess:
just check out what subtle issues you can run into by using this quite intuitive way of handling async resp. auto continuations: