Exemplo n.º 1
0
                public void OnNext(TLeft value)
                {
                    var s       = new Subject <TRight>();
                    var id      = 0;
                    var rightID = 0;

                    lock (_parent._gate)
                    {
                        id      = _parent._leftID++;
                        rightID = _parent._rightID;
                        _parent._leftMap.Add(id, s);
                    }

                    var window = new WindowObservable <TRight>(s, _parent._refCount);

                    // BREAKING CHANGE v2 > v1.x - Order of evaluation or the _leftDurationSelector and _resultSelector now consistent with Join.
                    var md = new SingleAssignmentDisposable();

                    _parent._group.Add(md);

                    var duration = default(IObservable <TLeftDuration>);

                    try
                    {
                        duration = _parent._leftDurationSelector(value);
                    }
                    catch (Exception exception)
                    {
                        OnError(exception);
                        return;
                    }

                    // BREAKING CHANGE v2 > v1.x - The duration sequence is subscribed to before the result sequence is evaluated.
                    md.Disposable = duration.SubscribeSafe(new DurationObserver(this, id, s, md));

                    var result = default(TResult);

                    try
                    {
                        result = _parent._resultSelector(value, window);
                    }
                    catch (Exception exception)
                    {
                        OnError(exception);
                        return;
                    }

                    lock (_parent._gate)
                    {
                        _parent._observer.OnNext(result);

                        foreach (var rightValue in _parent._rightMap)
                        {
                            if (rightValue.Key < rightID)
                            {
                                s.OnNext(rightValue.Value);
                            }
                        }
                    }
                }
Exemplo n.º 2
0
                    public void OnNext(TWindowClosing value)
                    {
                        lock (_parent._gate)
                        {
                            _parent._window.OnCompleted();
                            _parent._window = new Subject <TSource>();

                            var window = new WindowObservable <TSource>(_parent._window, _parent._refCountDisposable);
                            _parent.ForwardOnNext(window);
                        }
                    }
Exemplo n.º 3
0
                private void CloseWindow(IDisposable closingSubscription)
                {
                    closingSubscription.Dispose();

                    lock (_gate)
                    {
                        _window.OnCompleted();
                        _window = new Subject <TSource>();

                        var window = new WindowObservable <TSource>(_window, _refCountDisposable);
                        ForwardOnNext(window);
                    }

                    _windowGate.Wait(CreateWindowClose);
                }
Exemplo n.º 4
0
                public void Run(Boundaries parent)
                {
                    _window = new Subject <TSource>();

                    var d = new CompositeDisposable(2);

                    _refCountDisposable = new RefCountDisposable(d);

                    var window = new WindowObservable <TSource>(_window, _refCountDisposable);

                    ForwardOnNext(window);

                    d.Add(parent._source.SubscribeSafe(this));
                    d.Add(parent._windowBoundaries.SubscribeSafe(new WindowClosingObserver(this)));

                    SetUpstream(_refCountDisposable);
                }
Exemplo n.º 5
0
                public IDisposable Run(Boundaries parent)
                {
                    _window = new Subject <TSource>();

                    var d = new CompositeDisposable(2);

                    _refCountDisposable = new RefCountDisposable(d);

                    var window = new WindowObservable <TSource>(_window, _refCountDisposable);

                    base._observer.OnNext(window);

                    d.Add(parent._source.SubscribeSafe(this));
                    d.Add(parent._windowBoundaries.SubscribeSafe(new WindowClosingObserver(this)));

                    return(_refCountDisposable);
                }
Exemplo n.º 6
0
                public override void Run(IObservable <TSource> source)
                {
                    _window = new Subject <TSource>();

                    var groupDisposable = new CompositeDisposable(2)
                    {
                        _m
                    };

                    _refCountDisposable = new RefCountDisposable(groupDisposable);

                    var window = new WindowObservable <TSource>(_window, _refCountDisposable);

                    ForwardOnNext(window);

                    groupDisposable.Add(source.SubscribeSafe(this));

                    _windowGate.Wait(CreateWindowClose);

                    SetUpstream(_refCountDisposable);
                }
Exemplo n.º 7
0
                public IDisposable Run(IObservable <TSource> source)
                {
                    _window = new Subject <TSource>();

                    var groupDisposable = new CompositeDisposable(2)
                    {
                        _m
                    };

                    _refCountDisposable = new RefCountDisposable(groupDisposable);

                    var window = new WindowObservable <TSource>(_window, _refCountDisposable);

                    base._observer.OnNext(window);

                    groupDisposable.Add(source.SubscribeSafe(this));

                    _windowGate.Wait(CreateWindowClose);

                    return(_refCountDisposable);
                }
Exemplo n.º 8
0
                public override void OnNext(TLeft value)
                {
                    var s = new Subject <TRight>();

                    int id;
                    int rightID;

                    lock (_parent._gate)
                    {
                        id      = _parent._leftID++;
                        rightID = _parent._rightID;
                        _parent._leftMap.Add(id, s);
                    }

                    var window = new WindowObservable <TRight>(s, _parent._refCount);

                    // BREAKING CHANGE v2 > v1.x - Order of evaluation or the _leftDurationSelector and _resultSelector now consistent with Join.

                    IObservable <TLeftDuration> duration;

                    try
                    {
                        duration = _parent._leftDurationSelector(value);
                    }
                    catch (Exception exception)
                    {
                        OnError(exception);
                        return;
                    }

                    var durationObserver = new DurationObserver(this, id, s);

                    _parent._group.Add(durationObserver);
                    // BREAKING CHANGE v2 > v1.x - The duration sequence is subscribed to before the result sequence is evaluated.
                    durationObserver.SetResource(duration.SubscribeSafe(durationObserver));

                    TResult result;

                    try
                    {
                        result = _parent._resultSelector(value, window);
                    }
                    catch (Exception exception)
                    {
                        OnError(exception);
                        return;
                    }

                    lock (_parent._gate)
                    {
                        _parent.ForwardOnNext(result);

                        foreach (var rightValue in _parent._rightMap)
                        {
                            if (rightValue.Key < rightID)
                            {
                                s.OnNext(rightValue.Value);
                            }
                        }
                    }
                }