示例#1
0
    def test_starmap_dispose_inside_mapper(self):
        scheduler = TestScheduler()
        xs = scheduler.create_hot_observable(
            # 100 create
            on_next(110, (1, 10)),
            # 200 subscribe
            on_next(210, (2, 20)),
            on_next(310, (3, 30)),
            on_next(410, (4, 40)),
        )

        results = scheduler.create_observer()
        d = SerialDisposable()
        invoked = [0]

        def mapper(x, y):
            invoked[0] += 1
            if scheduler._clock > 250:
                d.dispose()
            return x + y

        d.disposable = xs.pipe(ops.starmap(mapper)).subscribe(results, scheduler)

        def action(scheduler, state):
            return d.dispose()

        scheduler.schedule_absolute(ReactiveTest.disposed, action)
        scheduler.start()

        assert results.messages == [on_next(110, 11), on_next(210, 22)]

        assert xs.subscriptions == [ReactiveTest.subscribe(0, 310)]
        assert invoked[0] == 3
示例#2
0
        def factory():
            def mapper(x, y):
                invoked[0] += 1
                if invoked[0] == 3:
                    raise Exception(ex)

                return x + y

            return xs.pipe(ops.starmap(mapper))
示例#3
0
    def test_starmap_subscription_error(self):
        mapper = ops.starmap(lambda x, y: (x, y))

        with self.assertRaises(RxException):
            return_value((1, 10)).pipe(mapper).subscribe(lambda x: _raise("ex"))

        with self.assertRaises(RxException):
            throw("ex").pipe(mapper).subscribe(on_error=lambda ex: _raise(ex))

        with self.assertRaises(RxException):
            empty().pipe(mapper).subscribe(
                lambda x: x, lambda ex: ex, lambda: _raise("ex")
            )

        def subscribe(observer, scheduler=None):
            _raise("ex")

        with self.assertRaises(RxException):
            create(subscribe).pipe(mapper).subscribe()
示例#4
0
        def factory():
            def mapper(x, y):
                invoked[0] += 1
                return x + y

            return xs.pipe(ops.starmap(mapper))
示例#5
0
        def factory():
            def mapper(*args):
                invoked[0] += 1
                return sum(args)

            return xs.pipe(ops.starmap(mapper))
示例#6
0
 def factory():
     return xs.pipe(ops.starmap())