Geeks With Blogs
Brian Schroer Don't Call Me Mort!

My late contribution to a debate that was raging almost a month ago now…

Regarding the upcoming C# 5 asynchronous programming improvements, Eric Lippert blogged about how Microsoft is aware that the "async" and "await" keywords, as shown below, imply the opposite of what they really mean:

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);

Regarding "await", Lippert said:

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.

It is unfortunate that people’s intuition upon first exposure regarding what the “async” and “await” contextual keywords mean is frequently the opposite of their actual meanings. Many attempts to come up with better keywords failed to find anything better. If you have ideas for a keyword or combination of keywords that is short, snappy, and gets across the correct ideas, I am happy to hear them.

My suggestion (which probably has been suggested by someone else - there was a ton of discussion on this, and it would take days to read all of it): Why not just use "async" instead of "await", e.g.:

var document = async FetchAsync(urls[i]);

I don't have a better suggestion for "async" for the method declaration keyword (I don't have a problem with it either). I also don't think it would be confusing to use "async" for both the method and statement keywords. We're "using" the same keyword in different contexts elsewhere in C# without confusion.

My other suggestion: Just make up a new word that doesn't imply any unwanted meaning. "asdf" is easy to type. Smile

Posted on Thursday, November 25, 2010 6:59 AM | Back to top

Comments on this post: Better keyword than "await" - How about "async"?

# re: Better keyword than "await" - How about "async"?
Requesting Gravatar...
asdf - ASyncDependantFunction Gets my vote ;)
Left by Fusspawn on Nov 29, 2010 9:08 PM

Your comment:
 (will show your gravatar)

Copyright © Brian Schroer | Powered by: