Asynchrony in C# 5.0 part Four: It’s not magic

Today I want to talk about asynchrony that does not involve any multithreading whatsoever. People keep on asking me “but how is it possible to have asynchrony without multithreading?” A strange question to ask because you probably already know the answer. Let me turn the question around: how is it possible to have multitasking without…

31

Asynchrony in C# 5, Part Three: Composition

I was walking to my bus the other morning at about 6:45 AM. Just as I was about to turn onto 45th street, a young man, shirtless, covered in blood ran down 45th at considerable speed right in front of me. Behind him was another fellow, wielding a baseball bat. My initial thought was “holy…

51

Asynchronous Programming in C# 5.0 part two: Whence await?

I want to start by being absolutely positively clear about two things, because our usability research has shown this to be confusing. Remember our little program from last time? 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)     …

161

Asynchrony in C# 5, Part One

The designers of C# 2.0 realized that writing iterator logic was painful. So they added iterator blocks. That way the compiler could figure out how to build a state machine that could store the continuation – the “what comes next” – in state somewhere, hidden behind the scenes, so that you don’t have to write…

61

Continuation Passing Style Revisited Part Five: CPS and Asynchrony

Today is when things are going to get really long and confusing. But we’ll make it through somehow. Consider the following task: you’ve got a list of URLs. You want to fetch the document associated with each URL. (Let’s suppose for the sake of argument that this always succeeds.) You then want to make a…

18

Continuation Passing Style Revisited Part Four: Turning yourself inside out

The obvious question at this point is: if CPS is so awesome then why don’t we use it all the time? Why have most professional developers never heard of it, or, those who have, think of it as something only those crazy Scheme programmers do? First of all, it is simply hard for most people…

6

Continuation Passing Style Revisited Part Three: Musings about coroutines

Last time I sketched briefly how one might implement interesting control flows like try-catch using continuations; as we saw, the actual implementations of Try and Throw are trivial once you have CPS. I’m sure that you could extend that work to implement try-catch-finally. Or, another basic exercise when learning about CPS you might try is…

20

Continuation Passing Style Revisited Part Two: Handwaving about control flow

Last time on Fabulous Adventures: “But we can construct arbitrarily complex control flows by keeping track of multiple continuations and deciding which one gets to go next.” Let’s look at an example of something more complex than a conditional. Consider a simplified version of “try-catch”, where there is no expression to the throw. A throw…

25

Continuation Passing Style Revisited, Part One

Good morning fabulous readers, let me just start by saying that this is going to get really long and really complicated but it will all pay off in the end. I’m also going to be posting on an accelerated schedule, more than my usual two posts per week. (It’ll eventually become clear why I’m doing…

31

Eric Lippert, from Microsoft?

No technology today, just an amusing story from a couple summers ago. Leah and I rent out a room in our house; I find it quite pleasant to live with a friend who pays my mortgage for me. One day a couple summers back our housemate K had her parents visiting from California. She and…

14