Exemple #1
0
    def subscribe(observer):
        enum = iter(sources)
        is_disposed = [False]
        subscription = SerialDisposable()

        def action(action1, state=None):
            if is_disposed[0]:
                return
            try:
                current = next(enum)
            except StopIteration:
                observer.on_completed()
            except Exception as ex:
                observer.on_error(ex)
            else:
                d = SingleAssignmentDisposable()
                subscription.disposable = d
                d.disposable = current.subscribe(
                    observer.on_next,
                    observer.on_error,
                    lambda: action1()
                )

        cancelable = immediate_scheduler.schedule_recursive(action)

        def dispose():
            is_disposed[0] = True
        return CompositeDisposable(subscription, cancelable, Disposable.create(dispose))
    def subscribe(observer):
        e = iter(sources)
        is_disposed = False
        subscription = SerialDisposable()

        def action(action1, state=None):
            current = None
            
            if is_disposed:
                return
            try:
                current = next(e)
            except StopIteration:
                observer.on_completed()    
            except Exception as ex:
                observer.on_error(ex)
            else:
                d = SingleAssignmentDisposable()
                subscription.disposable = d
                d.disposable = current.subscribe(
                    observer.on_next,
                    observer.on_error,
                    lambda: action1()
                )

        cancelable = immediate_scheduler.schedule_recursive(action)
        
        def dispose():
            nonlocal is_disposed
            is_disposed = True
        return CompositeDisposable(subscription, cancelable, Disposable(dispose))
Exemple #3
0
 def subscribe(observer):
     subscription = SerialDisposable()
     pos = [0]
     
     def action(this, state=None):
         if pos[0] < len(sources):
             current = Observable.from_future(sources[pos[0]])
             pos[0] += 1
             d = SingleAssignmentDisposable()
             subscription.disposable = d
             d.disposable = current.subscribe(observer.on_next, lambda ex: this(), lambda: this())
         else:
             observer.on_completed()
         
     cancelable = immediate_scheduler.schedule_recursive(action)
     return CompositeDisposable(subscription, cancelable)
    def subscribe(observer):
        subscription = SerialDisposable()

        def action(this, state=None):
            try:
                source = next(sources)
            except StopIteration:
                observer.on_completed()
                return

            # Allow source to be a factory method taking an error
            source = source(state) if callable(source) else source
            current = Observable.from_future(source)

            d = SingleAssignmentDisposable()
            subscription.disposable = d
            d.disposable = current.subscribe(observer.on_next, lambda ex: this(ex), this)

        cancelable = immediate_scheduler.schedule_recursive(action)
        return CompositeDisposable(subscription, cancelable)
        def subscribe(observer):
            subscription = SerialDisposable()
            pos = 0

            def action(this, state=None):
                nonlocal pos

                if pos < len(sources):
                    current = sources[pos]
                    pos += 1
                    d = SingleAssignmentDisposable()
                    subscription.disposable = d
                    d.disposable = current.subscribe(observer.on_next,
                                                     lambda ex: this(),
                                                     lambda: this())
                else:
                    observer.on_completed()

            cancelable = immediate_scheduler.schedule_recursive(action)
            return CompositeDisposable(subscription, cancelable)
Exemple #6
0
        def subscribe(observer):
            subscription = SerialDisposable()

            def action(this, state=None):
                try:
                    source = next(sources)
                except StopIteration:
                    observer.on_completed()
                    return

                # Allow source to be a factory method taking an error
                source = source(state) if callable(source) else source
                current = Observable.from_future(source)

                d = SingleAssignmentDisposable()
                subscription.disposable = d
                d.disposable = current.subscribe(observer.on_next,
                                                 lambda ex: this(ex), this)

            cancelable = immediate_scheduler.schedule_recursive(action)
            return CompositeDisposable(subscription, cancelable)
Exemple #7
0
    def subscribe(observer):
        e = iter(sources)
        is_disposed = False
        last_exception = None
        subscription = SerialDisposable()

        def action(action1, state=None):
            current = None

            def on_error(exn):
                nonlocal last_exception
                last_exception = exn
                action1()

            if is_disposed:
                return
            try:
                current = next(e)
            except StopIteration:
                if last_exception:
                    observer.on_error(last_exception)
                else:
                    observer.on_completed()
            except Exception as ex:
                observer.on_error(ex)
            else:
                d = SingleAssignmentDisposable()
                subscription.disposable = d

                d.disposable = current.subscribe(observer.on_next, on_error,
                                                 observer.on_completed)

        cancelable = immediate_scheduler.schedule_recursive(action)

        def dispose():
            nonlocal is_disposed
            is_disposed = True

        return CompositeDisposable(subscription, cancelable,
                                   Disposable(dispose))
Exemple #8
0
        def subscribe(observer):
            e = iter(sources)
            is_disposed = [False]
            last_exception = [None]
            subscription = SerialDisposable()

            def action(action1, state=None):
                current = None
                
                def on_error(exn):
                    last_exception[0] = exn
                    action1()

                if is_disposed[0]:
                    return
                try:
                    current = six.next(e)
                except StopIteration:
                    if last_exception[0]:
                        observer.on_error(last_exception[0])
                    else:
                        observer.on_completed()    
                except Exception as ex:
                    observer.on_error(ex)
                else:
                    d = SingleAssignmentDisposable()
                    subscription.disposable = d
                    
                    d.disposable = current.subscribe(
                        observer.on_next,
                        on_error,
                        observer.on_completed
                    )

            cancelable = immediate_scheduler.schedule_recursive(action)
            
            def dispose():
                is_disposed[0] = True
            return CompositeDisposable(subscription, cancelable, Disposable(dispose))