C# 8 : Asynchronous Streams and Static Local Functions

Asynchronous StreamHow often have you come across situations when you would want to return streams of data from an asynchronous method ? Plenty of times I would guess. The asynchronous methods were pretty limited when return data in streams, but not any longer.  Consider the following code. // Will not compile public static async Task<IEnumerable<int>> Generate(int max) { for (int i = 0; i < max; i++) { await Task.Delay(1000); yield return i; } } The above code would not compile. There is no way you could `yield return` values (or in other words, stream values) from an asynchronous method. This would have been a highly useful situation when you want to iterate over results from a query over an extremely large database. There are other countless situation the ability to stream data from asynchronous method could be useful. However, prior to C# 8.0, we were severely handicapped in such a situation. With C# 8.0, .Net comprises a new Type called the IAsyncEnumerable, which allows us to accomplis this. The above code could be now rewritten … Continue reading C# 8 : Asynchronous Streams and Static Local Functions

Managing Props as Component Developer

One of the little things one would have in mind when developing Components using React is that you might wonder if the developer who would consume the compoenent would pass in the required props. Let us consider a simple component here. export Navbar extends Component{ render (<div><h1>{this.props.title}</h1</div>) } The above Navbar components expects the props … Continue reading Managing Props as Component Developer

Asynchronous Code – Behind the Scenes – 004

During this series of deep dive into the asynchronous calls, we have so far looked into [x] General Structure of generated code.[x] Role of Stub/Worker method.[x] Structure of State Machine and role of Fields.[x] Implementation of the SetStateMachine method.[ ] Implementation of the MoveNext method. It is now time to look at the most important piece of the puzzle … Continue reading Asynchronous Code – Behind the Scenes – 004

Asynchronous Code – Behind the Scenes – 003

Okay, I wasn't quite realistic in the earlier post when I mentioned we would look at MoveNext in this one. I missed an important clog of the wheel. The SetStateMachine() method. IAsyncStateMachine.SetStateMachine We will only breifly visit the SetStateMachine method here, as the complete picture becomes more clear when we look to details of the MoveNext() method. So how does the SetStateMachine method … Continue reading Asynchronous Code – Behind the Scenes – 003

Asynchronous Code – Behind the Scenes – 002

In the earlier part of this series, we reviewed the generic structure of decompiled async code, especially the stub method. In this part, we would continue our explore of async code and look into the State Machine. We would not delve deep into the most important MoveNext() method yet, we will first familiar with the different parts … Continue reading Asynchronous Code – Behind the Scenes – 002