As usually described, it’s… (deep breath)… a function
A that accepts a function
B that will immediately be called by the language runtime, passing it a function
C that when eventually (optionally) called will cause the previous call to
A to return the argument previously passed to
C and so take us back to where we started – but only if
C was actually called. All clear?
No. Nobody ever learned what it’s for by reading a description like that. It’s the kind of description you can understand only if you’ve already had the thoughts that are expressed in it.
Well, my ambition in life is to explain it in a way that any reasonably experienced Java or C# programmer can understand, so I’ll put my current best effort here. Let me know if it helps, or hinders.
await facility in the C# 5 CTP is mightly reminiscent of the iterator methods (
yield return) added in C# 2. So much so that it is irresistable (to someone like me, anyway) to see if I can reinvent one using the other.
For many years now people have already been implementing something a lot like
yield return, and I’ve blogged about that before. It’s quite possible to write a simple library such that
yield return can play much the same role as
await, except for some irritating limitations.
But can we go the other way, and write a library that provides the capability of
yield return using only the new
Short answer: yes.
Long answer: (now read on…)