示例#1
0
        public override IDisposable Subscribe(IStreamObserver <TInnerKey, TSource> observer)
        {
            if (this.totalBranchesL2 <= 1)
            {
                return(this.Source.Subscribe(observer));
            }

            this.numBranches++;
            if (this.pipe == null)
            {
                this.pipe = CreatePipe(observer);
            }
            var o = observer;

            this.pipe.AddObserver(o);

            var d = o as IDisposable;

            if (this.numBranches < this.totalBranchesL2)
            {
                return(d ?? Utility.EmptyDisposable);
            }
            else
            {
                // Reset status for next set of subscribe calls
                var oldpipe = this.pipe;
                this.pipe        = null;
                this.numBranches = 0;

                return(d == null
                    ? this.Source.Subscribe(oldpipe)
                    : Utility.CreateDisposable(this.Source.Subscribe(oldpipe), d));
            }
        }
示例#2
0
        public override IDisposable Subscribe(IStreamObserver <TInnerKey, TSource> observer)
        {
            if (totalBranchesL2 <= 1)
            {
                return(singleThreadedShuffler.Subscribe(observer));
            }

            numBranches++;
            if (pipe == null)
            {
                if (this.Properties.IsColumnar && CanGenerateColumnar())
                {
                    pipe = GetPipe(observer, totalBranchesL2, shuffleId);
                }
                else
                {
                    pipe = CreatePipe(observer);
                }
            }
            var o = observer;

            pipe.AddObserver(o);

            var d = o as IDisposable;

            if (numBranches < totalBranchesL2)
            {
                return(d ?? Utility.EmptyDisposable);
            }
            else
            {
                // Reset status for next set of subscribe calls
                var oldpipe = pipe;
                pipe        = null;
                numBranches = 0;

                if (d == null)
                {
                    return(Source.Subscribe(oldpipe));
                }
                else
                {
                    return(Utility.CreateDisposable(Source.Subscribe(oldpipe), d));
                }
            }
        }