At the time of this writing, it??™s only available as part of the Microsoft
Robotics Studio,9 although hopefully that will change. We??™re not going to delve into
179 Pseudo-synchronous code with the Concurrency and Coordination Runtime
the depths of it??”fascinating as it is??”but it has one very interesting feature that??™s relevant
to this chapter. Rather than present real code that could compile and run (involving
pages and pages of description of the library), we??™ll just look at some pseudo-code
and the ideas behind it. The purpose of this section isn??™t to think too deeply about
asynchronous code, but to show how by adding intelligence to the compiler, a different
form of programming becomes feasible and reasonably elegant. The CCR uses
iterator blocks in an interesting way that takes a certain amount of mental effort to
start with. However, once you see the pattern it can lead to a radically different way of
thinking about asynchronous execution.
Suppose we??™re writing a server that needs to handle lots of requests. As part of
dealing with those requests, we need to first call a web service to fetch an authentication
token, and then use that token to get data from two independent data sources
(say a database and another web service). We then process that data and return the
result. Each of the fetch stages could take a while??”a second, say.
Pages:
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356