Create generator that yields coroutine results as the coroutines finish

asyncio.as_completed() takes an iterable of coroutines or futures and returns an iterable of futures in the order that the input futures complete. Normally, you’d loop over its result and await the members from inside an async function… import asyncio async def first(): await asyncio.sleep(5) return ‘first’ async def second(): await asyncio.sleep(1) return ‘second’ async def … Read more

RunAsync – How do I await the completion of work on the UI thread?

I found the following suggestion on a Microsoft github repository: How to await a UI task sent from a background thread. Setup Define this extension method for the CoreDispatcher: using System; using System.Threading.Tasks; using Windows.UI.Core; public static class DispatcherTaskExtensions { public static async Task<T> RunTaskAsync<T>(this CoreDispatcher dispatcher, Func<Task<T>> func, CoreDispatcherPriority priority = CoreDispatcherPriority.Normal) { var … Read more

Why does Console.In.ReadLineAsync block?

daryal provided the answer here http://smellegantcode.wordpress.com/2012/08/28/a-boring-discovery/ It seems ReadLineAsync is not actually doing what it’s supposed to do. Bug in the framework. My solution is to use ThreadPool.QueueUserWorkItem in a loop so each call to ReadLineAsync is done on a new thread.

AspNetSynchronizationContext

Am I correct that It does guarantee your continuations will get the same HttpContext.Current as original callers? It does not guarantee the continuations will execute on the same thread as the callers? Yes, HttpContext.Current is preserved, and yes, the continuations may execute on a different thread. I mean principal/culture associated with the thread and thread … Read more