public void OnSubscribe(IDisposable d)
        {
            try
            {
                onSubscribeCall(d);
            }
            catch (Exception e)
            {
                d.Dispose();
                EmptyDisposable.Error(actual, e);
                return;
            }

            actual.OnSubscribe(d);
        }
Esempio n. 2
0
        public void Subscribe(ISingleSubscriber <R> s)
        {
            ISingleSubscriber <T> sr;

            try
            {
                sr = onLift(s);
            }
            catch (Exception ex)
            {
                EmptyDisposable.Error(s, ex);
                return;
            }
            source.Subscribe(sr);
        }
Esempio n. 3
0
        public static ISingle <T> Defer <T>(Func <ISingle <T> > singleSupplier)
        {
            return(Create <T>(s =>
            {
                ISingle <T> single;

                try {
                    single = singleSupplier();
                } catch (Exception e)
                {
                    EmptyDisposable.Error(s, e);
                    return;
                }
                single.Subscribe(s);
            }));
        }
Esempio n. 4
0
        public static ICompletable Defer(Func <ICompletable> factory)
        {
            return(Create(cs =>
            {
                ICompletable c;

                try {
                    c = factory();
                } catch (Exception e)
                {
                    EmptyDisposable.Error(cs, e);
                    return;
                }

                c.Subscribe(cs);
            }));
        }
Esempio n. 5
0
        public static ICompletable Using <S>(
            Func <S> stateSupplier,
            Func <S, ICompletable> completableFactory,
            Action <S> stateDisposer,
            bool eager = true)
        {
            return(Create(cs =>
            {
                S state;

                try
                {
                    state = stateSupplier();
                }
                catch (Exception ex)
                {
                    EmptyDisposable.Error(cs, ex);
                    return;
                }

                ICompletable c;

                try
                {
                    c = completableFactory(state);
                }
                catch (Exception e)
                {
                    try
                    {
                        stateDisposer(state);
                    }
                    catch (Exception ex)
                    {
                        EmptyDisposable.Error(cs, new AggregateException(e, ex));
                        return;
                    }

                    EmptyDisposable.Error(cs, e);
                    return;
                }

                c.Subscribe(new UsingCompletableSubscriber(cs, eager, () => stateDisposer(state)));
            }));
        }
Esempio n. 6
0
        public static ISingle <T> Throw <T>(Func <Exception> errorSupplier)
        {
            return(Create <T>(s =>
            {
                Exception e;

                try
                {
                    e = errorSupplier();
                }
                catch (Exception ex)
                {
                    EmptyDisposable.Error(s, ex);
                    return;
                }
                EmptyDisposable.Error(s, e);
            }));
        }
Esempio n. 7
0
        public static ISingle <R> Zip <T, R>(this IEnumerable <ISingle <T> > sources, Func <T[], R> zipper)
        {
            return(Create <R>(s =>
            {
                int n = 0;

                ISingle <T>[] a = new ISingle <T> [8];

                foreach (ISingle <T> source in sources)
                {
                    if (n == a.Length)
                    {
                        ISingle <T>[] b = new ISingle <T> [n + (n >> 2)];
                        Array.Copy(a, 0, b, 0, n);
                        a = b;
                    }
                    a[n++] = source;
                }

                if (n == 0)
                {
                    EmptyDisposable.Error(s, NoSuchElementException());
                    return;
                }

                T[] array = new T[n];
                int[] counter = { n };

                SetCompositeDisposable all = new SetCompositeDisposable();

                s.OnSubscribe(all);

                for (int i = 0; i < n; i++)
                {
                    if (all.IsDisposed())
                    {
                        return;
                    }

                    a[i].Subscribe(new ZipSingleSubscriber <T, R>(s, i, array, counter, all, zipper));
                }
            }));
        }
Esempio n. 8
0
        public static ISingle <T> Using <T, S>(Func <S> stateSupplier, Func <S, ISingle <T> > singleFactory, Action <S> stateDisposer, bool eager = false)
        {
            return(Create <T>(s =>
            {
                S state;

                try
                {
                    state = stateSupplier();
                }
                catch (Exception e)
                {
                    EmptyDisposable.Error(s, e);
                    return;
                }

                ISingle <T> source;

                try {
                    source = singleFactory(state);
                }
                catch (Exception e)
                {
                    try
                    {
                        stateDisposer(state);
                    }
                    catch (Exception ex)
                    {
                        EmptyDisposable.Error(s, new AggregateException(e, ex));
                        return;
                    }

                    EmptyDisposable.Error(s, e);
                    return;
                }

                source.Subscribe(new UsingSingleSubscriber <T>(s, () => stateDisposer(state), eager));
            }));
        }