Click here to Skip to main content
13,087,797 members (78,779 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


3 bookmarked
Posted 12 Sep 2010

Marble Diagrams and Rx

, 27 Sep 2010
Rate this:
Please Sign up or sign in to vote.
A discussion about how to draw Marble Diagrams

Today I am going to discuss how to draw Marble Diagrams. I just came across it in the Reactive Framework. In Channel 9 videos, Jeffrey Van Gogh shows how to get started with Rx. Ever since I look deep into it, I find it very interesting, and perhaps a new way of thinking or understanding for Asynchronous programming structure. Reactive Framework introduces a few operators, which you might apply to an Observable to get the resultant observable. The way to represent each of these attributes can be done using Marble Diagrams.
Before you start dealing with Reactive Framework, it is good to start with IObservable and IObserver. I have already introduced with these two interfaces which are the building blocks for the Reactive Framework. You can read these articles before going through with Marble Diagrams.

How to Create a Marble Diagram

Marble diagram is basically a way to represent the Rx operations. You may think of a marble diagram to be a pictorial representation of different operators that are defined with Reactive Framework. Let's look at how to create a Marble Diagram:

So in the sample image, you can see that we measure Time in X-Axis while operations on Y-axis. Say for instance, you have an Observable which is represented by the first horizontal line. The small circles represent OnNext calls of IObserver. If you know already, read about Observable and Observer, you might already know that each Observer has the OnNext method, which gets invoked whenever the observer changes its state. Hence, in our case the observer invokes a function f() to get to the new State. The | represents the OnComplete for the Observer. So after OnComplete, the Observer will stop observing states.

We represents OnError using X in a marble diagram. In case of an Observable, OnError and OnComplete produces the end point for the observer. So, here after executing the two OnNext if the Observer encounters with an Exception, OnError gets invoked and the Observer will terminate.
So on the first image, we execute the function f() to get the new state with the Bottom Line. Now on, I am going to create a few Marble Diagrams, to make your understanding clear.


SelectMany is very easy to explain. Say you have two or more Observers. In this case, SelectMany will eventually invoke all the OnNext of each observer.

So if you have 3 observers, the SelectMany will produce Observer which aggregates all of them.

var ob1 = Observable.Return(5);
 var ob2 = Observable.Return(4);

 var ob3 = ob1.SelectMany(ob2);
 var disp = ob3.Subscribe(   r => Console.WriteLine("OnNext"), 
                             r => Console.WriteLine("Completed"), 
                            () => Console.WriteLine("Error"));

So the Observer will select from each of the Observers and get you the output.

In case of an error, the final Observer will stop when the first error of any Observer is encountered.

SkipUntil / SkipWhile

SkipWhile and SkipUntil work in opposite. Say for instance, you have two Observables. SkipUntil gives you OnNext for each of them until the OnNext from the other observer is received. On the contrary, SkipWhile will produce OnNext for the Observer while the OnNext from the second observer is received. When the second observer is Complete or gives an error, the final observer will terminate in case of SkipWhile.

So in the above diagrams, you can see While will bypass all the values until the second observer receives an entry.

Further Reference

To learn the operators of Marble Diagrams, you can see the latest Videos on Channel 9. Here are a few more Operators:

I hope this will help you to understand the Marble Diagrams, and hope these will describe some more operators of Rx Framework.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Abhishek Sur
India India
Did you like his post?

Oh, lets go a bit further to know him better.
Visit his Website : to know more about Abhishek.

Abhishek also authored a book on .NET 4.5 Features and recommends you to read it, you will learn a lot from it.

Basically he is from India, who loves to explore the .NET world. He loves to code and in his leisure you always find him talking about technical stuffs.

Presently he is working in WPF, a new foundation to UI development, but mostly he likes to work on architecture and business classes. ASP.NET is one of his strength as well.
Have any problem? Write to him in his Forum.

You can also mail him directly to

Want a Coder like him for your project?
Drop him a mail to

Visit His Blog

Dotnet Tricks and Tips

Dont forget to vote or share your comments about his Writing

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170813.1 | Last Updated 27 Sep 2010
Article Copyright 2010 by Abhishek Sur
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid