Challenge #8 Better Solution

2015/08/17

last week I was hanging out with friends and like geek often do we was speaking about Rx . when it come to the solution for Challenge #8 ,Eric Rabinovitch suggest much better solution than I had. today I managed to have the time for putting Eric’s idea into code and I came out with shorter and more elegant solution.   before I post the solution I will put short reminder for the issue I’m about to solve. the challenge was all about buffering the data on suspension period and flush it out on resume. the...
no comments

Async Local

2015/08/14

following the previous post about .NET 4.5 new Async API this post will focus on AsyncLocal API the subject of this post brought to my awareness while speaking with my  colleagues Yuval Detinis and Ido Flatow. AsyncLocal<T> solving the problem of maintaining call context for logical call rather than the thread context. while working with async / await or asynchronous API in general keeping the call context may become a problem. the thread context may not represent the logical call context. putting data on the thread local storage may be bad idea while working...
no comments

.NET 4.5 new Async API

the new .NET 4.6 and Visual Studio 2015 major features like Roslyn, RyuJIT  musk some other cool feature like async API additions. this post will put some light on a few basic API and will be followed by post about AsyncLocal<T>. .NET 4.6  was adding some convenient API: Code Snippet Task.CompletedTask; var cts = new CancellationTokenSource(100); Task.FromCanceled(cts.Token); Task.FromException(new TimeoutException()); those API may seem silly for newbies but developer which familiar with async code style may find this API’s very useful for abstracting the synchronous /  asynchronous boundaries and for reducing memory footprint for some async...
no comments

Rx Challenge #8 Solution

2015/07/29

this post is part of series, the hole series can be found in here. this challenge was all about buffering the data on suspension period and flush it out on resume. the idea is to suspend the observable notification for a while without loosing data. the following diagram show the required functionality Marble Diagram /************************************************* * source  ---1---2---3---4---5---6---7---8---9---10---11-| * hold    -------------T-----------F-----------T---------| * result  ---1---2---3-------------4567--8---9-----------10,11-| *************************************************/ solving this problem require some kind of buffering and if you follow my blog you must know that when it come to buffer and dispatch I’m usually integrating...
no comments

Rx Challenge #8

2015/07/24

this post is part of series, the hole series can be found in here.   this challenge is all about buffering data while suspended and flush it out on resume. we already had challenge on Suspend and Resume but that challenge ignored the data during the suspension period. on this challenge you expected to buffer the data during the suspension period and flush it out on resume. to achieve this challenge you have to provide extension method on the following format: Code Snippet public static IObservable<T> HoldWhile<T>(             this IObservable<T> source,             IObservable<bool> hold) {     /*************************************************...
no comments

Rx Challenge TOC

2015/07/17

this is a quick access page to the Rx Challenges Questions #1 http://blogs.microsoft.co.il/bnaya/2015/01/27/rx-challenge/ #2 http://blogs.microsoft.co.il/bnaya/2015/02/05/rx-challenge-2/ #3 http://blogs.microsoft.co.il/bnaya/2015/03/06/rx-challenge-3/ #4 http://blogs.microsoft.co.il/bnaya/2015/03/25/rx-challenge-4/ #5 http://blogs.microsoft.co.il/bnaya/2015/04/03/rx-challenge-5/ #6 http://blogs.microsoft.co.il/bnaya/2015/04/10/rx-challenge-6/ #7 http://blogs.microsoft.co.il/bnaya/2015/07/11/rx-challenge-7/   Solutions #1 http://blogs.microsoft.co.il/bnaya/2015/01/31/rx-challenge-solution/ #2 http://blogs.microsoft.co.il/bnaya/2015/02/09/rx-challenge-2-solution/ #3 http://blogs.microsoft.co.il/bnaya/2015/03/25/rx-challenge-3-solution/ #4 http://blogs.microsoft.co.il/bnaya/2015/03/30/rx-challenge-4-solution/      http://blogs.microsoft.co.il/bnaya/2015/04/02/rx-challenge-4-more-solution/ #5 http://blogs.microsoft.co.il/bnaya/2015/04/10/rx-challenge-5-solution/ #6 http://blogs.microsoft.co.il/bnaya/2015/04/19/rx-challenge-6-solution/ #7 http://blogs.microsoft.co.il/bnaya/2015/07/17/rx-challenge-7-solution/
no comments

Rx Challenge #7 Solution

the last challenge was about extending Rx API to support WhereAsync. while following Rx guidelines to ensure keeping events in order and synchronized “Assume observer instances are called in a serialized fashion” page 8, synchronization of async events may not be so trivial, solving it may require message buffering and dispatching. with that in mind, you can either build custom buffering and dispatching component or use existing one like TPL Dataflow. it turn out that this is exactly what TPL Dataflow design for. more than that, TPL Dataflow integrate smoothly with Rx .   the following solution is...
no comments

Rx Challenge #7

2015/07/11

this challenge is all about extending the Rx API to support WhereAsync let take the following scenario: var xs = Observable.Interval(TimeSpan.FromMinutes(1)); what if you’re having the following method which get long and return Task<bool> Code Snippet public async Task<bool> IsValidAsync(long value) {     // in real life the method may send     // the to a service and get whether it's     // ok to use it     await Task.Delay(1000);     return value % 2 == 0; } can you filter the observable using this method? the problem...
no comments

Custom Task Scheduler and await

2015/06/03

on this post I will discuss the behavior of async and await when it's come to scheduling. let take the following snippet: 1: private async Task DoSomethingAsync() 2: { 3: // which thread is executing here? 4: // is it UI thread? 5: // is it Thread Pool thread? 6:  7: await Task.Delay(100); 8:  9:...
no comments

Rx Challenge #6 Solution

2015/04/19

the previous challenge was about weakening the reference to the subscriber. you can see the challenge here. my solution for this challenge involve WeakObserver class + extension method which will create mediator of the weak observer each subscription. the following code snippet describe my solution: public class WeakObserver<T> : IObserver<T>{ private readonly WeakReference<IObserver<T>> _target; #region Ctor /// <summary> /// Initializes a new instance of the <see cref="WeakObserver{T}"/> class. /// </summary> /// <param name="target">The target.</param> /// <exception cref="System.ArgumentNullException">target</exception>...
no comments