O'Reilly logo

Programming Reactive Extensions and LINQ by Paul Betts, Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implementing Your Own Operators

While Rx provides a number of operators to manage even very complex programming situations, there will be times when you need to customize the behavior for your specific goal.

Since operators in both Rx and LINQ are simply extension methods on IObservable and IEnumerable, it's easy to create your own. The simplest way to create your own operators is by combining existing operators.

We'll use Aggregate in a clever way, since it already encapsulates “return a value when the input completes.” We'll use the First method to do the blocking for us.

public static class BlockingObservableMixins {     public static void BlockUntilCompleted<T>(this IObservable<T> input)     {         input.Aggregate(0, (acc, x) => acc) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required