def test_reduce_single_flowables_with_maintaining_order(self):
        reduce_multicast = CollectFlowablesMultiCast(
            source=self.source_multicast,
            maintain_order=True,
        )
        reduce_multicast.get_source(self.info).subscribe(self.rx_sink)
        self.source_multicast.on_next(Flowable(self.source1))
        self.source_multicast.on_next(Flowable(self.source2))
        self.source_multicast.on_completed()

        sink = TObserver()
        subscription = self.rx_sink.received[0].unsafe_subscribe(Subscriber(
            scheduler=self.source_scheduler,
            subscribe_scheduler=self.source_scheduler
        ))
        subscription.observable.observe(init_observer_info(observer=sink))

        # sending the lifted flowable is scheduled on the multicast_scheduler
        self.multicast_scheduler.advance_by(1)
        self.source_scheduler.advance_by(1)

        self.source1.on_next_single(1)
        self.source2.on_next_single('a')
        self.source1.on_next_single(2)
        self.source1.on_completed()
        self.source2.on_next_single('b')
        self.source2.on_completed()

        self.assertEqual([1, 2, 'a', 'b'], sink.received)
        self.assertTrue(sink.is_completed)
    def test_send_dictionary(self):
        reduce_multicast = CollectFlowablesMultiCast(source=self.source_multicast)
        reduce_multicast.get_source(self.info).subscribe(self.rx_sink)

        self.source_multicast.on_next({'f1': Flowable(self.source1)})

        self.assertEqual(1, len(self.rx_sink.received))
Example #3
0
    def test_subscribe_single_flowable(self):
        reduce_multicast = LoopFlowableMultiCast(
            source=self.source_multicast,
            func=lambda m: MultiCast(m).pipe(
                rxbp.multicast.op.map(lambda t: t[0]), ),
            initial=[10],
        )
        reduce_multicast.get_source(self.info).subscribe(self.rx_sink)
        self.source_multicast.on_next(Flowable(self.source1))

        sink = TObserver(immediate_continue=0)
        subscription = self.rx_sink.received[0].unsafe_subscribe(
            Subscriber(
                scheduler=self.source_scheduler,
                subscribe_scheduler=self.source_scheduler,
            ))
        subscription.observable.observe(init_observer_info(sink))

        self.multicast_scheduler.advance_by(1)
        self.source_scheduler.advance_by(1)

        # self.source1.on_next_single(0)

        print(sink.received)

        self.assertEqual([10], sink.received)
    def test_send_single_flowable(self):
        reduce_multicast = SharedMultiCast(source=self.source_multicast)
        observable = reduce_multicast.get_source(self.info)

        observable.subscribe(self.rx_sink1)
        observable.subscribe(self.rx_sink2)

        self.source_multicast.on_next(Flowable(self.source1))

        self.assertEqual(1, len(self.rx_sink1.received))
        self.assertEqual(1, len(self.rx_sink2.received))
Example #5
0
    def test_send_single_flowable(self):
        reduce_multicast = LoopFlowableMultiCast(
            source=self.source_multicast,
            func=lambda m: MultiCast(m).pipe(
                rxbp.multicast.op.map(lambda t: t[0]), ),
            initial=[0],
        )
        reduce_multicast.get_source(self.info).subscribe(self.rx_sink)

        self.source_multicast.on_next(Flowable(self.source1))

        self.assertEqual(1, len(self.rx_sink.received))
    def test_use_case(self):
        sink = TObserver()
        subscription = rxbp.merge(
            *[Flowable(e) for e in self.sources]).unsafe_subscribe(
                Subscriber(scheduler=self.scheduler,
                           subscribe_scheduler=self.scheduler))
        subscription.observable.observe(init_observer_info(observer=sink))

        self.sources[0].observable.on_next_single(1)
        self.sources[1].observable.on_next_single(2)
        self.sources[2].observable.on_next_single(3)

        self.scheduler.advance_by(1)

        self.assertEqual([1, 2, 3], sink.received)
Example #7
0
        def func(builder: ImperativeMultiCastBuilder):
            builder = ImperativeMultiCastBuilder(
                source_scheduler=self.scheduler,
                composite_disposable=self.composite_disposable,
            )

            s1[0] = builder.create_multicast_subject()
            s2[0] = builder.create_flowable_subject()
            s3[0] = builder.create_flowable_subject()

            # s1[0].to_flowable().subscribe(observer=self.sink1, scheduler=self.scheduler)
            s2[0].subscribe(observer=self.sink2, scheduler=self.scheduler)

            blocking_flowable = Flowable(self.source)

            def output_selector(flowable: Flowable):
                return rxbp.multicast.return_flowable(flowable)

            return builder.return_(
                blocking_flowable=blocking_flowable,
                output_selector=output_selector,
            )