Beispiel #1
0
        public IDisposable SubscribeRaw(IObserver <TTarget> observer, bool enableSafeguard)
        {
            ISafeObserver <TTarget> safeObserver = null;

            //
            // See AutoDetachObserver.cs for more information on the safeguarding requirement and
            // its implementation aspects.
            //
            if (enableSafeguard)
            {
                observer = safeObserver = SafeObserver <TTarget> .Wrap(observer);
            }

            var sink = CreateSink(observer);

            safeObserver?.SetResource(sink);

            if (CurrentThreadScheduler.IsScheduleRequired)
            {
                CurrentThreadScheduler.Instance.ScheduleAction(
                    (@this: this, sink),
                    tuple => [email protected](tuple.sink));
            }
            else
            {
                Run(sink);
            }

            return(sink);
        }
Beispiel #2
0
        public IDisposable SubscribeRaw(IObserver <TSource> observer, bool enableSafeguard)
        {
            IDisposable             run;
            ISafeObserver <TSource> safeObserver = null;

            //
            // See AutoDetachObserver.cs for more information on the safeguarding requirement and
            // its implementation aspects.
            //
            if (enableSafeguard)
            {
                observer = safeObserver = SafeObserver <TSource> .Wrap(observer);
            }

            if (CurrentThreadScheduler.IsScheduleRequired)
            {
                var runAssignable = new SingleAssignmentDisposable();

                CurrentThreadScheduler.Instance.ScheduleAction(
                    (@this: this, runAssignable, observer),
                    tuple => tuple.runAssignable.Disposable = [email protected](tuple.observer));

                run = runAssignable;
            }
            else
            {
                run = Run(observer);
            }

            safeObserver?.SetResource(run);
            return(run);
        }