/Rx 1.0.10605/Source/Rxx/System/Reactive/PairedObservableExtensions.cs
C# | 147 lines | 88 code | 16 blank | 43 comment | 24 complexity | 6d2152bca4f2a6972f76b96eec8ad4e0 MD5 | raw file
- using System.Diagnostics.Contracts;
- using System.Reactive.Linq;
-
- namespace System.Reactive
- {
- /// <summary>
- /// Provides extension methods for <see cref="System.Reactive.IPairedObservable{TLeft,TRight}"/>.
- /// </summary>
- public static class PairedObservableExtensions
- {
- /// <summary>
- /// Notifies the observable that an observer is to receive notifications.
- /// </summary>
- /// <typeparam name="TLeft">Type of the left notification channel.</typeparam>
- /// <typeparam name="TRight">Type of the right notification channel.</typeparam>
- /// <param name="source">The observable for which a subscription is created.</param>
- /// <param name="onNextLeft">The handler of notifications in the left channel.</param>
- /// <param name="onNextRight">The handler of notifications in the right channel.</param>
- /// <returns>The observer's interface that enables cancelation of the subscription so that it stops receiving notifications.</returns>
- public static IDisposable SubscribePair<TLeft, TRight>(
- this IObservable<Either<TLeft, TRight>> source,
- Action<TLeft> onNextLeft,
- Action<TRight> onNextRight)
- {
- Contract.Requires(source != null);
- Contract.Requires(onNextLeft != null);
- Contract.Requires(onNextRight != null);
- Contract.Ensures(Contract.Result<IDisposable>() != null);
-
- var disposable = source.Subscribe(PairedObserver.Create(
- onNextLeft,
- onNextRight));
-
- #if SILVERLIGHT
- Contract.Assume(disposable != null);
- #endif
-
- return disposable;
- }
-
- /// <summary>
- /// Notifies the observable that an observer is to receive notifications.
- /// </summary>
- /// <typeparam name="TLeft">Type of the left notification channel.</typeparam>
- /// <typeparam name="TRight">Type of the right notification channel.</typeparam>
- /// <param name="source">The observable for which a subscription is created.</param>
- /// <param name="onNextLeft">The handler of notifications in the left channel.</param>
- /// <param name="onNextRight">The handler of notifications in the right channel.</param>
- /// <param name="onError">The handler of an error notification.</param>
- /// <returns>The observer's interface that enables cancelation of the subscription so that it stops receiving notifications.</returns>
- public static IDisposable SubscribePair<TLeft, TRight>(
- this IObservable<Either<TLeft, TRight>> source,
- Action<TLeft> onNextLeft,
- Action<TRight> onNextRight,
- Action<Exception> onError)
- {
- Contract.Requires(source != null);
- Contract.Requires(onNextLeft != null);
- Contract.Requires(onNextRight != null);
- Contract.Requires(onError != null);
- Contract.Ensures(Contract.Result<IDisposable>() != null);
-
- var disposable = source.Subscribe(PairedObserver.Create(
- onNextLeft,
- onNextRight,
- onError));
-
- #if SILVERLIGHT
- Contract.Assume(disposable != null);
- #endif
-
- return disposable;
- }
-
- /// <summary>
- /// Notifies the observable that an observer is to receive notifications.
- /// </summary>
- /// <typeparam name="TLeft">Type of the left notification channel.</typeparam>
- /// <typeparam name="TRight">Type of the right notification channel.</typeparam>
- /// <param name="source">The observable for which a subscription is created.</param>
- /// <param name="onNextLeft">The handler of notifications in the left channel.</param>
- /// <param name="onNextRight">The handler of notifications in the right channel.</param>
- /// <param name="onCompleted">The handler of a completion notification.</param>
- /// <returns>The observer's interface that enables cancelation of the subscription so that it stops receiving notifications.</returns>
- public static IDisposable SubscribePair<TLeft, TRight>(
- this IObservable<Either<TLeft, TRight>> source,
- Action<TLeft> onNextLeft,
- Action<TRight> onNextRight,
- Action onCompleted)
- {
- Contract.Requires(source != null);
- Contract.Requires(onNextLeft != null);
- Contract.Requires(onNextRight != null);
- Contract.Requires(onCompleted != null);
- Contract.Ensures(Contract.Result<IDisposable>() != null);
-
- var disposable = source.Subscribe(PairedObserver.Create(
- onNextLeft,
- onNextRight,
- onCompleted));
-
- #if SILVERLIGHT
- Contract.Assume(disposable != null);
- #endif
-
- return disposable;
- }
-
- /// <summary>
- /// Notifies the observable that an observer is to receive notifications.
- /// </summary>
- /// <typeparam name="TLeft">Type of the left notification channel.</typeparam>
- /// <typeparam name="TRight">Type of the right notification channel.</typeparam>
- /// <param name="source">The observable for which a subscription is created.</param>
- /// <param name="onNextLeft">The handler of notifications in the left channel.</param>
- /// <param name="onNextRight">The handler of notifications in the right channel.</param>
- /// <param name="onError">The handler of an error notification.</param>
- /// <param name="onCompleted">The handler of a completion notification.</param>
- /// <returns>The observer's interface that enables cancelation of the subscription so that it stops receiving notifications.</returns>
- public static IDisposable SubscribePair<TLeft, TRight>(
- this IObservable<Either<TLeft, TRight>> source,
- Action<TLeft> onNextLeft,
- Action<TRight> onNextRight,
- Action<Exception> onError,
- Action onCompleted)
- {
- Contract.Requires(source != null);
- Contract.Requires(onNextLeft != null);
- Contract.Requires(onNextRight != null);
- Contract.Requires(onError != null);
- Contract.Requires(onCompleted != null);
- Contract.Ensures(Contract.Result<IDisposable>() != null);
-
- var disposable = source.Subscribe(PairedObserver.Create(
- onNextLeft,
- onNextRight,
- onError,
- onCompleted));
-
- #if SILVERLIGHT
- Contract.Assume(disposable != null);
- #endif
-
- return disposable;
- }
- }
- }