Пример #1
0
    def test_should_emit_from_the_point_of_subscription_forward(self):
        subject = PublishObservableSubject(scheduler=self.scheduler)
        s1 = TObservable(observer=subject)

        self.assertIsInstance(s1.on_next_iter([1]), ContinueAck)
        self.assertIsInstance(s1.on_next_iter([2]), ContinueAck)
        self.assertIsInstance(s1.on_next_iter([3]), ContinueAck)

        o1 = TObserver()
        o1.immediate_continue = 5

        subject.observe(init_observer_info(o1))

        self.assertIsInstance(s1.on_next_iter([4]), ContinueAck)
        self.assertIsInstance(s1.on_next_iter([5]), ContinueAck)
        self.assertIsInstance(s1.on_next_iter([6]), ContinueAck)
        s1.on_completed()

        self.assertEqual(sum(o1.received), 15)
        self.assertTrue(o1.is_completed)
    def test_on_next_assynchronously_iterate_in_fast_loop(self):
        """
                 on_next
        queue = [] -> queue = [OnNext(2)]
        """

        # preparation
        o1 = TObserver(immediate_continue=0)
        self.subject.observe(init_observer_info(o1))
        self.source.on_next_single(1)
        self.source.on_next_single(2)
        self.source.on_next_single(3)

        # state change
        o1.immediate_continue = 1  # needs immediate continue to loop
        o1.ack.on_next(continue_ack)
        self.scheduler.advance_by(1)

        # validation
        self.assertEqual([1, 2, 3], o1.received)
        self.assertEqual(0, len(self.subject.shared_state.queue))
Пример #3
0
 def gen_observers():
     for i in range(10):
         o1 = TObserver()
         o1.immediate_continue = 5
         subject.observe(init_observer_info(o1))
         yield o1