Niner Interview Questions: Rico Mariani - Visual Studio Futures (Interview is Complete)
I find this quite useful and it probably does make developing code faster in some circumstances.
Thanks Jeff
IEnumerator<ITask> CcrReadFileAsync(string file)
{
var result = new Port<IAsyncResult>();
using (var fs = new FileStream(file,…,FileOptions.Asynchronous))
{
var buf = new byte[fs.Length];
fs.BeginRead(buf, 0, buf.Length, result.Post, null);
yield return result.Receive();
var ar = (IAsyncResult)resultPort.Test();
try {
fs.EndRead(ar);
ProcessData(buf);
} catch { // handle exception }
}
}
Thank you my dear friend. I like you and your books.............
Hi Jeffrey,
I wanted to show your video about the AsyncEnumerator to a colleague, but it seems to have disappeared from Channel9...
Was that a result of a conscious action, or did something go wrong? Is there any other place I can find it? - Peter
Fixed. Thanks for letting us know!
C
This seems to be an implementation of trampoline-style threading in .Net.
You write your code as a method which periodically gives up control of its calling thread by use of the "yield" statement. And you expect that the scheduler/engine will revive you so that you can continue from where you left off.
This same technique can be used to write multi-threaded programs in single-thread languages such as javascript: http://blog.monstuff.com/archives/000315.html
This technique would benefit from C# supporting the "yield foreach" construction. This would allow for an iterator method calling into another iterator method passing the result directly through. This is an especially useful syntax and optimization for recusive calls (tree navigation).
Read more on "yield foreach" at https://blogs.msdn.com/wesdyer/archive/2007/03/23/all-about-iterators.aspx