예제 #1
0
        public static IDisposable Subscribe <T>(this IObservable <T> source, Func <IObserver <object> > observerFactory)
        {
            Contract.Requires(observerFactory != null);
            Contract.Ensures(Contract.Result <IDisposable>() != null);

            Contract.Assume(source != null);

            var observer = new TypeCoercingObserver <T, object>(observerFactory());

            return(source.Subscribe(observer));
        }
예제 #2
0
        public static void ForEach <T>(this IEnumerable <T> source, Func <IObserver <object> > observerFactory)
        {
            Contract.Requires(source != null);
            Contract.Requires(observerFactory != null);

            var observer = new TypeCoercingObserver <T, object>(observerFactory());

            try
            {
                source.ForEach(observer.OnNext);
            }
            catch (Exception ex)
            {
                observer.OnError(ex);
            }

            observer.OnCompleted();
        }
예제 #3
0
        public static void ForEach <T>(this IObservable <T> source, Func <IObserver <object> > observerFactory)
        {
            Contract.Requires(observerFactory != null);

            Contract.Assume(source != null);

            var observer = new TypeCoercingObserver <T, object>(observerFactory());

            try
            {
#if !WINDOWS_PHONE
                source.ForEachAsync(observer.OnNext).Wait();
#else
                source.ForEach(observer.OnNext);
#endif
            }
            catch (Exception ex)
            {
                observer.OnError(ex);
                return;
            }

            observer.OnCompleted();
        }