def subscribe(observer, scheduler_=None):
            _scheduler = scheduler or scheduler_ or TimeoutScheduler.singleton()

            n = [0]
            s = [None]
            timer_d = SerialDisposable()
            window_id = [0]
            group_disposable = CompositeDisposable(timer_d)
            ref_count_disposable = RefCountDisposable(group_disposable)

            def create_timer(_id):
                m = SingleAssignmentDisposable()
                timer_d.disposable = m

                def action(scheduler, state):
                    if _id != window_id[0]:
                        return

                    n[0] = 0
                    window_id[0] += 1
                    new_id = window_id[0]
                    s[0].on_completed()
                    s[0] = Subject()
                    observer.on_next(add_ref(s[0], ref_count_disposable))
                    create_timer(new_id)

                m.disposable = _scheduler.schedule_relative(timespan, action)

            s[0] = Subject()
            observer.on_next(add_ref(s[0], ref_count_disposable))
            create_timer(0)

            def on_next(x):
                new_window = False
                new_id = 0

                s[0].on_next(x)
                n[0] += 1
                if n[0] == count:
                    new_window = True
                    n[0] = 0
                    window_id[0] += 1
                    new_id = window_id[0]
                    s[0].on_completed()
                    s[0] = Subject()
                    observer.on_next(add_ref(s[0], ref_count_disposable))

                if new_window:
                    create_timer(new_id)

            def on_error(e):
                s[0].on_error(e)
                observer.on_error(e)

            def on_completed():
                s[0].on_completed()
                observer.on_completed()

            group_disposable.add(source.subscribe_(on_next, on_error, on_completed, scheduler_))
            return ref_count_disposable
Exemplo n.º 2
0
        def subscribe(observer, scheduler=None):
            window_subject = Subject()
            d = CompositeDisposable()
            r = RefCountDisposable(d)

            observer.on_next(add_ref(window_subject, r))

            def on_next_window(x):
                window_subject.on_next(x)

            def on_error(err):
                window_subject.on_error(err)
                observer.on_error(err)

            def on_completed():
                window_subject.on_completed()
                observer.on_completed()

            d.add(
                source.subscribe_(on_next_window, on_error, on_completed,
                                  scheduler))

            def on_next_observer(w):
                nonlocal window_subject
                window_subject.on_completed()
                window_subject = Subject()
                observer.on_next(add_ref(window_subject, r))

            d.add(
                boundaries.subscribe_(on_next_observer, on_error, on_completed,
                                      scheduler))
            return r
Exemplo n.º 3
0
        def subscribe(observer):
            window = Subject()
            d = CompositeDisposable()
            r = RefCountDisposable(d)

            observer.on_next(add_ref(window, r))

            def on_next_window(x):
                window.on_next(x)
            
            def on_error(err):
                window.on_error(err)
                observer.on_error(err)
            
            def on_completed():
                window.on_completed()
                observer.on_completed()

            d.add(source.subscribe(on_next_window, on_error, on_completed))

            def on_next_observer(w):
                window.on_completed()
                window = Subject()
                observer.on_next(add_ref(window, r))
            
            d.add(window_boundaries.subscribe(on_next_observer, on_error, on_copleted))
            return r
Exemplo n.º 4
0
        def subscribe(observer, scheduler_=None):
            _scheduler = scheduler or scheduler_ or timeout_scheduler

            n = [0]
            s = [None]
            timer_d = SerialDisposable()
            window_id = [0]
            group_disposable = CompositeDisposable(timer_d)
            ref_count_disposable = RefCountDisposable(group_disposable)

            def create_timer(_id):
                m = SingleAssignmentDisposable()
                timer_d.disposable = m

                def action(scheduler, state):
                    if _id != window_id[0]:
                        return

                    n[0] = 0
                    window_id[0] += 1
                    new_id = window_id[0]
                    s[0].on_completed()
                    s[0] = Subject()
                    observer.on_next(add_ref(s[0], ref_count_disposable))
                    create_timer(new_id)

                m.disposable = _scheduler.schedule_relative(timespan, action)

            s[0] = Subject()
            observer.on_next(add_ref(s[0], ref_count_disposable))
            create_timer(0)

            def on_next(x):
                new_window = False
                new_id = 0

                s[0].on_next(x)
                n[0] += 1
                if n[0] == count:
                    new_window = True
                    n[0] = 0
                    window_id[0] += 1
                    new_id = window_id[0]
                    s[0].on_completed()
                    s[0] = Subject()
                    observer.on_next(add_ref(s[0], ref_count_disposable))

                if new_window:
                    create_timer(new_id)

            def on_error(e):
                s[0].on_error(e)
                observer.on_error(e)

            def on_completed():
                s[0].on_completed()
                observer.on_completed()

            group_disposable.add(source.subscribe_(on_next, on_error, on_completed, scheduler_))
            return ref_count_disposable
Exemplo n.º 5
0
    def subscribe(observer, scheduler=None):
        window = [Subject()]
        d = CompositeDisposable()
        r = RefCountDisposable(d)

        observer.on_next(add_ref(window[0], r))

        def on_next_window(x):
            window[0].on_next(x)

        def on_error(err):
            window[0].on_error(err)
            observer.on_error(err)

        def on_completed():
            window[0].on_completed()
            observer.on_completed()

        d.add(source.subscribe_(on_next_window, on_error, on_completed, scheduler))

        def on_next_observer(w):
            window[0].on_completed()
            window[0] = Subject()
            observer.on_next(add_ref(window[0], r))

        d.add(window_boundaries.subscribe_(on_next_observer, on_error, on_completed, scheduler))
        return r
Exemplo n.º 6
0
 def receive_headers(self, b: bytes):
     self.buffer += b
     eor = self.buffer.find(b'\r\n\r\n')
     if eor >= 0:
         headers = self.buffer[:eor]
         remainder = self.buffer[eor + 4:]
         self.buffer = b''
         try:
             request = self.parse(headers)
             self.content_remaining = request.content_length
             if self.content_remaining:
                 self.receiving_headers = False
                 self.content_in = BufferedSubject()
                 request.content_in = add_ref(self.content_in, self.ref_count_disposable)
                 self.observer.on_next(request)
                 if remainder:
                     self.receive_body(remainder)
             else:
                 self.observer.on_next(request)
                 if remainder:
                     self.receive_headers(remainder)
         except HttpResponse as e:
             self.observer.on_error(e)
         except Exception as e:
             self.observer.on_error(BadRequest(repr(e).encode()))
Exemplo n.º 7
0
                def action(scheduler, state):
                    if _id != window_id[0]:
                        return

                    n[0] = 0
                    window_id[0] += 1
                    new_id = window_id[0]
                    s[0].on_completed()
                    s[0] = Subject()
                    observer.on_next(add_ref(s[0], ref_count_disposable))
                    create_timer(new_id)
Exemplo n.º 8
0
                def action(scheduler, state):
                    if _id != window_id[0]:
                        return

                    n[0] = 0
                    window_id[0] += 1
                    new_id = window_id[0]
                    s[0].on_completed()
                    s[0] = Subject()
                    observer.on_next(add_ref(s[0], ref_count_disposable))
                    create_timer(new_id)
Exemplo n.º 9
0
                def action(scheduler, state):
                    nonlocal n, s, window_id
                    if _id != window_id:
                        return

                    n = 0
                    window_id += 1
                    new_id = window_id
                    s.on_completed()
                    s = Subject()
                    observer.on_next(add_ref(s, ref_count_disposable))
                    create_timer(new_id)
Exemplo n.º 10
0
 def action(scheduler, state):
     nonlocal n, s, window_id
     if _id != window_id:
         return
     
     n = 0
     window_id += 1
     new_id = window_id
     s.on_completed()
     s = Subject()
     observer.on_next(add_ref(s, ref_count_disposable))
     create_timer(new_id)
Exemplo n.º 11
0
            def on_next_left(value):
                s = Subject()
                _id = left_id
                left_id += 1
                left_map.add(_id, s)
                
                try:
                    result = result_selector(value, add_ref(s, r))
                except Exception as e:
                    log.error("*** Exception: %s" % e)
                    left_values = left_map.getValues()
                    for left_value in left_values:
                        left_value.on_error(e)
                    
                    observer.on_error(e)
                    return
                
                observer.on_next(result)

                right_values = right_map.getValues()
                for right_value in right_values:
                    s.on_next(right_value)
                
                md = SingleAssignmentDisposable()
                group.add(md)

                def expire():
                    if left_map.remove(_id):
                        s.on_completed()
                    
                    group.remove(md)
                
                try:
                    duration = left_duration_selector(value)
                except Exception as e:
                    left_values = left_map.getValues()
                    for left_value in left_values:
                        left_value.on_error(e)
                    
                    observer.on_error(e)
                    return
                
                def on_error(e):
                    left_values = left_map.getValues()
                    for left_value in left_values:
                        left_value.on_error(e)
                    
                    observer.on_error(e)
                    
                md.disposable = duration.take(1).subscribe(
                    nothing,
                    on_error,
                    expire)
Exemplo n.º 12
0
            def on_next_left(value):
                s = Subject()

                with self.lock:
                    _id = left_id[0]
                    left_id[0] += 1
                    left_map[_id] = s

                try:
                    result = result_selector(value, add_ref(s, r))
                except Exception as e:
                    log.error("*** Exception: %s" % e)
                    for left_value in left_map.values():
                        left_value.on_error(e)

                    observer.on_error(e)
                    return

                observer.on_next(result)

                for right_value in right_map.values():
                    s.on_next(right_value)

                md = SingleAssignmentDisposable()
                group.add(md)

                def expire():
                    if _id in left_map:
                        del left_map[_id]
                        s.on_completed()

                    group.remove(md)

                try:
                    duration = left_duration_selector(value)
                except Exception as e:
                    for left_value in left_map.values():
                        left_value.on_error(e)

                    observer.on_error(e)
                    return

                def on_error(e):
                    for left_value in left_map.values():
                        left_value.on_error(e)

                    observer.on_error(e)

                md.disposable = duration.take(1).subscribe(
                    nothing,
                    on_error,
                    expire)
Exemplo n.º 13
0
        def on_next_left(value):
            s = Subject()

            with self.lock:
                _id = left_id[0]
                left_id[0] += 1
                left_map[_id] = s

            try:
                result = result_selector(value, add_ref(s, r))
            except Exception as e:
                log.error("*** Exception: %s" % e)
                for left_value in left_map.values():
                    left_value.on_error(e)

                observer.on_error(e)
                return

            observer.on_next(result)

            for right_value in right_map.values():
                s.on_next(right_value)

            md = SingleAssignmentDisposable()
            group.add(md)

            def expire():
                if _id in left_map:
                    del left_map[_id]
                    s.on_completed()

                group.remove(md)

            try:
                duration = left_duration_selector(value)
            except Exception as e:
                for left_value in left_map.values():
                    left_value.on_error(e)

                observer.on_error(e)
                return

            def on_error(e):
                for left_value in left_map.values():
                    left_value.on_error(e)

                observer.on_error(e)

            md.disposable = duration.take(1).subscribe(
                nothing,
                on_error,
                expire)
Exemplo n.º 14
0
                def action(scheduler, state=None):
                    s = None

                    if is_shift:
                        s = Subject()
                        q.append(s)
                        observer.on_next(add_ref(s, ref_count_disposable))

                    if is_span:
                        s = q.pop(0)
                        s.on_completed()

                    create_timer()
Exemplo n.º 15
0
                def action(scheduler, state=None):
                    s = None

                    if is_shift:
                        s = Subject()
                        q.append(s)
                        observer.on_next(add_ref(s, ref_count_disposable))

                    if is_span:
                        s = q.pop(0)
                        s.on_completed()

                    create_timer()
Exemplo n.º 16
0
            def on_next_left(value):
                subject = Subject()

                with left.lock:
                    _id = left_id[0]
                    left_id[0] += 1
                    left_map[_id] = subject

                try:
                    result = (value, add_ref(subject, rcd))
                except Exception as e:
                    log.error("*** Exception: %s" % e)
                    for left_value in left_map.values():
                        left_value.on_error(e)

                    observer.on_error(e)
                    return

                observer.on_next(result)

                for right_value in right_map.values():
                    subject.on_next(right_value)

                md = SingleAssignmentDisposable()
                group.add(md)

                def expire():
                    if _id in left_map:
                        del left_map[_id]
                        subject.on_completed()

                    group.remove(md)

                try:
                    duration = left_duration_mapper(value)
                except Exception as e:
                    for left_value in left_map.values():
                        left_value.on_error(e)

                    observer.on_error(e)
                    return

                def on_error(error):
                    for left_value in left_map.values():
                        left_value.on_error(error)

                    observer.on_error(error)

                md.disposable = duration.pipe(ops.take(1)).subscribe_(
                    nothing, on_error, expire, scheduler)
Exemplo n.º 17
0
            def on_next_left(value):
                subject = Subject()

                with left.lock:
                    _id = left_id[0]
                    left_id[0] += 1
                    left_map[_id] = subject

                try:
                    result = (value, add_ref(subject, rcd))
                except Exception as e:
                    log.error("*** Exception: %s" % e)
                    for left_value in left_map.values():
                        left_value.on_error(e)

                    observer.on_error(e)
                    return

                observer.on_next(result)

                for right_value in right_map.values():
                    subject.on_next(right_value)

                md = SingleAssignmentDisposable()
                group.add(md)

                def expire():
                    if _id in left_map:
                        del left_map[_id]
                        subject.on_completed()

                    group.remove(md)

                try:
                    duration = left_duration_mapper(value)
                except Exception as e:
                    for left_value in left_map.values():
                        left_value.on_error(e)

                    observer.on_error(e)
                    return

                def on_error(error):
                    for left_value in left_map.values():
                        left_value.on_error(error)

                    observer.on_error(error)

                md.disposable = duration.pipe(ops.take(1)).subscribe_(nothing, on_error, expire, scheduler)
Exemplo n.º 18
0
            def on_next(x):
                new_window = False
                new_id = 0

                s[0].on_next(x)
                n[0] += 1
                if n[0] == count:
                    new_window = True
                    n[0] = 0
                    window_id[0] += 1
                    new_id = window_id[0]
                    s[0].on_completed()
                    s[0] = Subject()
                    observer.on_next(add_ref(s[0], ref_count_disposable))

                if new_window:
                    create_timer(new_id)
Exemplo n.º 19
0
            def on_next(x):
                new_window = False
                new_id = 0

                s[0].on_next(x)
                n[0] += 1
                if n[0] == count:
                    new_window = True
                    n[0] = 0
                    window_id[0] += 1
                    new_id = window_id[0]
                    s[0].on_completed()
                    s[0] = Subject()
                    observer.on_next(add_ref(s[0], ref_count_disposable))

                if new_window:
                    create_timer(new_id)
Exemplo n.º 20
0
            def on_next(x):
                nonlocal s, n, window_id

                new_window = False
                new_id = 0

                s.on_next(x)
                n += 1
                if n == count:
                    new_window = True
                    n = 0
                    window_id += 1
                    new_id = window_id
                    s.on_completed()
                    s = Subject()
                    observer.on_next(add_ref(s, ref_count_disposable))

                if new_window:
                    create_timer(new_id)
Exemplo n.º 21
0
 def on_next(x):
     nonlocal s, n, window_id
     
     new_window = False
     new_id = 0
     
     s.on_next(x)
     n += 1
     if n == count:
         new_window = True
         n = 0
         window_id += 1
         new_id = window_id
         s.on_completed()
         s = Subject()
         observer.on_next(add_ref(s, ref_count_disposable))
     
     if new_window:
         create_timer(new_id)
Exemplo n.º 22
0
        def subscribe(observer, scheduler=None):
            m = SerialDisposable()
            d = CompositeDisposable(m)
            r = RefCountDisposable(d)
            window = Subject()

            observer.on_next(add_ref(window, r))

            def on_next(value):
                window.on_next(value)

            def on_error(error):
                window.on_error(error)
                observer.on_error(error)

            def on_completed():
                window.on_completed()
                observer.on_completed()

            d.add(source.subscribe_(on_next, on_error, on_completed,
                                    scheduler))

            def create_window_on_completed():
                try:
                    window_close = closing_mapper()
                except Exception as exception:
                    observer.on_error(exception)
                    return

                def on_completed():
                    nonlocal window
                    window.on_completed()
                    window = Subject()
                    observer.on_next(add_ref(window, r))
                    create_window_on_completed()

                m1 = SingleAssignmentDisposable()
                m.disposable = m1
                m1.disposable = window_close.pipe(ops.take(1)).subscribe_(
                    noop, on_error, on_completed, scheduler)

            create_window_on_completed()
            return r
Exemplo n.º 23
0
    def subscribe(observer):
        m = SerialDisposable()
        d = CompositeDisposable(m)
        r = RefCountDisposable(d)
        window = [Subject()]

        observer.on_next(add_ref(window[0], r))

        def on_next(x):
            window[0].on_next(x)

        def on_error(ex):
            window[0].on_error(ex)
            observer.on_error(ex)

        def on_completed():
            window[0].on_completed()
            observer.on_completed()

        d.add(source.subscribe(on_next, on_error, on_completed))

        def create_window_close():
            try:
                window_close = window_closing_selector()
            except Exception as exception:
                log.error("*** Exception: %s" % exception)
                observer.on_error(exception)
                return

            def on_completed():
                window[0].on_completed()
                window[0] = Subject()
                observer.on_next(add_ref(window[0], r))
                create_window_close()

            m1 = SingleAssignmentDisposable()
            m.disposable = m1
            m1.disposable = window_close.take(1).subscribe(
                noop, on_error, on_completed)

        create_window_close()
        return r
        def subscribe(observer):
            m = SerialDisposable()
            d = CompositeDisposable(m)
            r = RefCountDisposable(d)
            window = Subject()
            
            observer.on_next(add_ref(window, r))

            def on_next(x):
                window.on_next(x)
            
            def on_error(ex):
                window.on_error(ex)
                observer.on_error(ex)
            
            def on_completed():
                window.on_completed()
                observer.on_completed()
            
            d.add(source.subscribe(on_next, on_error, on_completed))
            
            def create_window_close():
                try:
                    window_close = window_closing_selector()
                except Exception as exception:
                    log.error("*** Exception: %s" % exception)
                    observer.on_error(exception)
                    return
                
                def on_completed():
                    window.on_completed()
                    window = Subject()
                    observer.on_next(add_ref(window, r))
                    create_window_close()
                
                m1 = SingleAssignmentDisposable()
                m.disposable(m1)
                m1.disposable(window_close.take(1).subscribe(noop, on_error, on_completed))
            
            create_window_close()
            return r        
Exemplo n.º 25
0
    def subscribe(observer, scheduler=None):
        m = SerialDisposable()
        d = CompositeDisposable(m)
        r = RefCountDisposable(d)
        window = [Subject()]

        observer.on_next(add_ref(window[0], r))

        def on_next(value):
            window[0].on_next(value)

        def on_error(error):
            window[0].on_error(error)
            observer.on_error(error)

        def on_completed():
            window[0].on_completed()
            observer.on_completed()

        d.add(source.subscribe_(on_next, on_error, on_completed, scheduler))

        def create_window_on_completed():
            try:
                window_close = window_closing_mapper()
            except Exception as exception:
                observer.on_error(exception)
                return

            def on_completed():
                window[0].on_completed()
                window[0] = Subject()
                observer.on_next(add_ref(window[0], r))
                create_window_on_completed()

            m1 = SingleAssignmentDisposable()
            m.disposable = m1
            m1.disposable = window_close.pipe(ops.take(1)).subscribe_(noop, on_error, on_completed, scheduler)

        create_window_on_completed()
        return r
Exemplo n.º 26
0
 def on_completed():
     window[0].on_completed()
     window[0] = Subject()
     observer.on_next(add_ref(window[0], r))
     create_window_on_completed()
Exemplo n.º 27
0
 def create_window():
     s = Subject()
     q.append(s)
     observer.on_next(add_ref(s, refCountDisposable))
Exemplo n.º 28
0
        def subscribe(observer, scheduler_=None):
            _scheduler = scheduler or scheduler_ or timeout_scheduler

            timer_d = SerialDisposable()
            next_shift = [timeshift]
            next_span = [timespan]
            total_time = [DELTA_ZERO]
            q = []

            group_disposable = CompositeDisposable(timer_d)
            ref_count_disposable = RefCountDisposable(group_disposable)

            def create_timer():
                m = SingleAssignmentDisposable()
                timer_d.disposable = m
                is_span = False
                is_shift = False

                if next_span[0] == next_shift[0]:
                    is_span = True
                    is_shift = True
                elif next_span[0] < next_shift[0]:
                    is_span = True
                else:
                    is_shift = True

                new_total_time = next_span[0] if is_span else next_shift[0]

                ts = new_total_time - total_time[0]
                total_time[0] = new_total_time
                if is_span:
                    next_span[0] += timeshift

                if is_shift:
                    next_shift[0] += timeshift

                def action(scheduler, state=None):
                    s = None

                    if is_shift:
                        s = Subject()
                        q.append(s)
                        observer.on_next(add_ref(s, ref_count_disposable))

                    if is_span:
                        s = q.pop(0)
                        s.on_completed()

                    create_timer()
                m.disposable = _scheduler.schedule_relative(ts, action)

            q.append(Subject())
            observer.on_next(add_ref(q[0], ref_count_disposable))
            create_timer()

            def on_next(x):
                for s in q:
                    s.on_next(x)

            def on_error(e):
                for s in q:
                    s.on_error(e)

                observer.on_error(e)

            def on_completed():
                for s in q:
                    s.on_completed()

                observer.on_completed()

            group_disposable.add(source.subscribe_(on_next, on_error, on_completed, scheduler_))
            return ref_count_disposable
Exemplo n.º 29
0
        def subscribe(observer):
            timerD = SerialDisposable()
            next_shift = timeshift
            next_span = timespan
            total_time = timedelta(0)
            q = []
            
            group_disposable = CompositeDisposable(timerD)
            ref_count_disposable = RefCountDisposable(group_disposable)
            
            def create_timer():
                nonlocal q, total_time, next_span, next_shift

                m = SingleAssignmentDisposable()
                timerD.disposable = m
                is_span = False
                is_shift = False

                if next_span == next_shift:
                    is_span = True
                    is_shift = True
                elif next_span < next_shift:
                    is_span = True
                else:
                    is_shift = True
                
                new_total_time = next_span if is_span else next_shift

                ts = new_total_time - total_time
                total_time = new_total_time
                if is_span:
                    next_span += timeshift
                
                if is_shift:
                    next_shift += timeshift
                
                def action(scheduler, state=None):
                    s = None
                    
                    if is_shift:
                        s = Subject()
                        q.append(s)
                        observer.on_next(add_ref(s, ref_count_disposable))
                    
                    if is_span:
                        s = q.pop(0)
                        s.on_completed()
                    
                    create_timer()
                m.disposable = scheduler.schedule_relative(ts, action)
            
            q.append(Subject())
            observer.on_next(add_ref(q[0], ref_count_disposable))
            create_timer()
            
            def on_next(x):
                for s in q:
                    s.on_next(x)
            
            def on_error(e):
                for s in q:
                    s.on_error(e)
                
                observer.on_error(e)
            
            def on_completed():
                for s in q:
                    s.on_completed()
                
                observer.on_completed()
            
            group_disposable.add(source.subscribe(on_next, on_error, on_completed))
            return ref_count_disposable
Exemplo n.º 30
0
        def subscribe(observer, scheduler_=None):
            _scheduler = scheduler or scheduler_ or timeout_scheduler

            timer_d = SerialDisposable()
            next_shift = [timeshift]
            next_span = [timespan]
            total_time = [DELTA_ZERO]
            q = []

            group_disposable = CompositeDisposable(timer_d)
            ref_count_disposable = RefCountDisposable(group_disposable)

            def create_timer():
                m = SingleAssignmentDisposable()
                timer_d.disposable = m
                is_span = False
                is_shift = False

                if next_span[0] == next_shift[0]:
                    is_span = True
                    is_shift = True
                elif next_span[0] < next_shift[0]:
                    is_span = True
                else:
                    is_shift = True

                new_total_time = next_span[0] if is_span else next_shift[0]

                ts = new_total_time - total_time[0]
                total_time[0] = new_total_time
                if is_span:
                    next_span[0] += timeshift

                if is_shift:
                    next_shift[0] += timeshift

                def action(scheduler, state=None):
                    s = None

                    if is_shift:
                        s = Subject()
                        q.append(s)
                        observer.on_next(add_ref(s, ref_count_disposable))

                    if is_span:
                        s = q.pop(0)
                        s.on_completed()

                    create_timer()

                m.disposable = _scheduler.schedule_relative(ts, action)

            q.append(Subject())
            observer.on_next(add_ref(q[0], ref_count_disposable))
            create_timer()

            def on_next(x):
                for s in q:
                    s.on_next(x)

            def on_error(e):
                for s in q:
                    s.on_error(e)

                observer.on_error(e)

            def on_completed():
                for s in q:
                    s.on_completed()

                observer.on_completed()

            group_disposable.add(
                source.subscribe_(on_next, on_error, on_completed, scheduler_))
            return ref_count_disposable
Exemplo n.º 31
0
 def on_completed():
     nonlocal window
     window.on_completed()
     window = Subject()
     observer.on_next(add_ref(window, r))
     create_window_on_completed()
Exemplo n.º 32
0
        def subscribe(observer):
            n = 0
            s = None
            timerD = SerialDisposable()
            window_id = 0
            group_disposable = CompositeDisposable(timerD)
            ref_count_disposable = RefCountDisposable(group_disposable)
            
            def create_timer(_id):
                m = SingleAssignmentDisposable()
                timerD.disposable = m

                def action(scheduler, state):
                    nonlocal n, s, window_id
                    if _id != window_id:
                        return
                    
                    n = 0
                    window_id += 1
                    new_id = window_id
                    s.on_completed()
                    s = Subject()
                    observer.on_next(add_ref(s, ref_count_disposable))
                    create_timer(new_id)
        
                m.disposable = scheduler.schedule_relative(timespan, action)
            
            s = Subject()
            observer.on_next(add_ref(s, ref_count_disposable))
            create_timer(0)
            
            def on_next(x):
                nonlocal s, n, window_id
                
                new_window = False
                new_id = 0
                
                s.on_next(x)
                n += 1
                if n == count:
                    new_window = True
                    n = 0
                    window_id += 1
                    new_id = window_id
                    s.on_completed()
                    s = Subject()
                    observer.on_next(add_ref(s, ref_count_disposable))
                
                if new_window:
                    create_timer(new_id)

            def on_error(e):
                s.on_error(e)
                observer.on_error(e)

            def on_completed():
                s.on_completed()
                observer.on_completed()
            
            group_disposable.add(source.subscribe(on_next, on_error, on_completed))
            return ref_count_disposable    
Exemplo n.º 33
0
        def subscribe(observer):
            n = 0
            s = None
            timerD = SerialDisposable()
            window_id = 0
            group_disposable = CompositeDisposable(timerD)
            ref_count_disposable = RefCountDisposable(group_disposable)

            def create_timer(_id):
                m = SingleAssignmentDisposable()
                timerD.disposable = m

                def action(scheduler, state):
                    nonlocal n, s, window_id
                    if _id != window_id:
                        return

                    n = 0
                    window_id += 1
                    new_id = window_id
                    s.on_completed()
                    s = Subject()
                    observer.on_next(add_ref(s, ref_count_disposable))
                    create_timer(new_id)

                m.disposable = scheduler.schedule_relative(timespan, action)

            s = Subject()
            observer.on_next(add_ref(s, ref_count_disposable))
            create_timer(0)

            def on_next(x):
                nonlocal s, n, window_id

                new_window = False
                new_id = 0

                s.on_next(x)
                n += 1
                if n == count:
                    new_window = True
                    n = 0
                    window_id += 1
                    new_id = window_id
                    s.on_completed()
                    s = Subject()
                    observer.on_next(add_ref(s, ref_count_disposable))

                if new_window:
                    create_timer(new_id)

            def on_error(e):
                s.on_error(e)
                observer.on_error(e)

            def on_completed():
                s.on_completed()
                observer.on_completed()

            group_disposable.add(
                source.subscribe(on_next, on_error, on_completed))
            return ref_count_disposable
Exemplo n.º 34
0
 def on_next_observer(w):
     window.on_completed()
     window = Subject()
     observer.on_next(add_ref(window, r))
Exemplo n.º 35
0
 def on_next_observer(w):
     nonlocal window_subject
     window_subject.on_completed()
     window_subject = Subject()
     observer.on_next(add_ref(window_subject, r))
Exemplo n.º 36
0
 def on_completed():
     window.on_completed()
     window = Subject()
     observer.on_next(add_ref(window, r))
     create_window_close()
Exemplo n.º 37
0
        def subscribe(observer):
            timerD = SerialDisposable()
            next_shift = timeshift
            next_span = timespan
            total_time = timedelta(0)
            q = []

            group_disposable = CompositeDisposable(timerD)
            ref_count_disposable = RefCountDisposable(group_disposable)

            def create_timer():
                nonlocal q, total_time, next_span, next_shift

                m = SingleAssignmentDisposable()
                timerD.disposable = m
                is_span = False
                is_shift = False

                if next_span == next_shift:
                    is_span = True
                    is_shift = True
                elif next_span < next_shift:
                    is_span = True
                else:
                    is_shift = True

                new_total_time = next_span if is_span else next_shift

                ts = new_total_time - total_time
                total_time = new_total_time
                if is_span:
                    next_span += timeshift

                if is_shift:
                    next_shift += timeshift

                def action(scheduler, state=None):
                    s = None

                    if is_shift:
                        s = Subject()
                        q.append(s)
                        observer.on_next(add_ref(s, ref_count_disposable))

                    if is_span:
                        s = q.pop(0)
                        s.on_completed()

                    create_timer()

                m.disposable = scheduler.schedule_relative(ts, action)

            q.append(Subject())
            observer.on_next(add_ref(q[0], ref_count_disposable))
            create_timer()

            def on_next(x):
                for s in q:
                    s.on_next(x)

            def on_error(e):
                for s in q:
                    s.on_error(e)

                observer.on_error(e)

            def on_completed():
                for s in q:
                    s.on_completed()

                observer.on_completed()

            group_disposable.add(
                source.subscribe(on_next, on_error, on_completed))
            return ref_count_disposable
Exemplo n.º 38
0
 def create_window():
     s = Subject()
     q.append(s)
     observer.on_next(add_ref(s, refCountDisposable))
Exemplo n.º 39
0
 def on_completed():
     window[0].on_completed()
     window[0] = Subject()
     observer.on_next(add_ref(window[0], r))
     create_window_on_completed()