Task.Delay Challenge Solution

2017/04/21

Task.Delay Challenge Solution This post suggest solution to the Task.Delay challenge. If you haven’t read the Task.Delay challenge you can find it here. In nutshell the challenge was about making Task.Delay like functionality which is test-able (using IScheduler for having virtual time). In order to support virtual time I will use Rx’s stream (which is also awaitable). The original Task.Delay is actually having 2 different completion path: - Complete by time. - Complete as result of cancellation token event. The general idea of the solution is to have 2 Rx’s streams one for each completion path: - Timer...
no comments

Task.Delay Challenge

2017/04/14

Task.Delay Challenge Task.Delay can be useful in many scenarios, for example: periodic execution.  Traditionally periodic execution done by using Timer API. Periodic execution with Task.Delay is easy for debug and better for maintain. The following code show the pattern: Code Snippet private async Task PeriodicJobAsync(CancellationToken token) {     var duration = TimeSpan.FromSeconds(5);     while (!token.IsCancellationRequested)     {         try         {             await Task.Delay(duration, token);         }         catch (OperationCanceledException) { }           // Process the job     } } The problem start when you want to test the code without waiting the real-world duration.   The challenge...
no comments

SDP Teaser

2017/04/04

This is a short teaser for what I’m planning to talk about in the next upcoming SDP conference. If you happened to be in Israel on May 2017 you can still register to the talk. The audience for this session expected to have prior knowledge about TPL,  async / await and parallel programming in general. On this full day workshop I will focus on the less familiar aspects and patterns.   Beyond Async And Await Planed Agenda * Task from different angle * Task.Run vs Task.Factory.StartNew * async / await drill down and custom awaitable * Some...