def on_next(self, elem: ElementType): obs_list: List[Observable] = [self.selector(e) for e in elem] for observable in obs_list: place_holder = self.PlaceHolder( observer=None, ) merge_obs = MergeObservable( left=observable, right=place_holder, ) parent, other = self.place_holders # def observe_on_subscribe_scheduler(_, __, merge_obs=merge_obs, parent=parent): # return merge_obs.observe(self.observer_info.copy(observer=parent.observer)) # # # make sure that Trampoline Scheduler is active # if self.subscribe_scheduler.idle: # disposable = self.subscribe_scheduler.schedule(observe_on_subscribe_scheduler) # else: # disposable = observe_on_subscribe_scheduler(None, None) disposable = merge_obs.observe(init_observer_info( observer=parent.observer, )) self.composite_disposable.add(disposable) self.place_holders = (other, place_holder) return continue_ack
def test_init_state(self): sink = TObserver() obs = MergeObservable(self.s1, self.s2) obs.observe(init_observer_info(sink)) self.assertIsInstance(self.measure_termination_state(obs), TerminationStates.InitState) self.assertIsInstance(self.measure_state(obs), MergeStates.NoneReceived)
def test_left_complete_to_error_asynchronous_ack(self): sink = TObserver(immediate_continue=0) obs = MergeObservable(self.s1, self.s2) obs.observe(init_observer_info(sink)) self.s1.on_completed() self.s2.on_error(self.exception) self.assertIsInstance(self.measure_termination_state(obs), TerminationStates.ErrorState) self.assertIsInstance(self.measure_state(obs), MergeStates.Stopped) self.assertEqual(self.exception, sink.exception)
def test_emit_left_with_asynchronous_ack(self): """ s1.on_next NoneReceived ------------> NoneReceivedWaitAck """ sink = TObserver(immediate_continue=0) obs = MergeObservable(self.s1, self.s2) obs.observe(init_observer_info(sink)) left_ack = self.s1.on_next_single(1) self.assertIsInstance(self.measure_state(obs), MergeStates.NoneReceivedWaitAck) self.assertEqual(sink.received, [1]) self.assertIsInstance(left_ack, ContinueAck)
def test_right_complete_on_async_ack(self): """ """ sink = TObserver(immediate_continue=0) obs = MergeObservable(self.s1, self.s2) obs.observe(init_observer_info(sink)) self.s1.on_completed() self.s2.on_next_single(1) ack = self.s2.on_next_single(2) self.s2.on_completed() sink.ack.on_next(continue_ack) self.assertEqual([1, 2], sink.received) self.assertTrue(sink.is_completed)
def test_acknowledge_non_received(self): """ ack.on_next NoneReceivedWaitAck ------------> NoneReceived """ sink = TObserver(immediate_continue=0) obs = MergeObservable(self.s1, self.s2) obs.observe(init_observer_info(sink)) self.s1.on_next_single(1) sink.ack.on_next(continue_ack) self.assertIsInstance(self.measure_state(obs), MergeStates.NoneReceived) self.assertEqual(sink.received, [1])
def __post_init__(self): self.place_holders = (self.PlaceHolder(observer=None), self.PlaceHolder(observer=None)) disposable = MergeObservable( left=self.place_holders[0], right=self.place_holders[1], ).observe(init_observer_info(observer=self.observer)) self.composite_disposable.add(disposable)
def test_left_complete_on_async_ack2(self): """ """ sink = TObserver(immediate_continue=0) obs = MergeObservable(self.s1, self.s2) obs.observe(init_observer_info(sink)) self.s1.on_next_single(1) self.s1.on_next_single(2) ack = self.s2.on_next_single(11) self.s1.on_completed() sink.ack.on_next(continue_ack) sink.ack.on_next(continue_ack) self.assertEqual([1, 2, 11], sink.received) self.assertIsInstance(ack.value, ContinueAck)
def test_wait_ack_and_continue_with_asynchronous_ack(self): """ ack.on_next Stopped -------------> Stopped """ sink = TObserver(immediate_continue=0) obs = MergeObservable(self.s1, self.s2) obs.observe(init_observer_info(sink)) self.s1.on_next_single(1) self.s1.on_completed() self.s2.on_completed() sink.ack.on_next(continue_ack) self.assertIsInstance(self.measure_state(obs), MergeStates.Stopped) self.assertEqual(sink.received, [1])
def test_none_received_to_right_received_with_asynchronous_ack(self): """ s2.on_next NoneReceivedWaitAck ------------> RightReceived """ sink = TObserver(immediate_continue=0) obs = MergeObservable(self.s1, self.s2) obs.observe(init_observer_info(sink)) self.s1.on_next_single(2) left_ack = self.s1.on_next_single(2) self.assertIsInstance(self.measure_state(obs), MergeStates.LeftReceived) self.assertEqual(sink.received, [2]) self.assertFalse(left_ack.has_value)
def test_emit_right_with_synchronous_ack(self): """ s2.on_next NoneReceived ------------> NoneReceived InitState InitState """ sink = TObserver() obs = MergeObservable(self.s1, self.s2) obs.observe(init_observer_info(sink)) self.s2.on_next_single(2) self.assertIsInstance(self.measure_termination_state(obs), TerminationStates.InitState) self.assertIsInstance(self.measure_state(obs), MergeStates.NoneReceived) self.assertEqual(sink.received, [2])
def test_left_complete_on_complete_right(self): """ s1.on_completed NoneReceived -----------------> NoneReceived InitState LeftCompletedState """ sink = TObserver() obs = MergeObservable(self.s1, self.s2) obs.observe(init_observer_info(sink)) self.s1.on_completed() self.s2.on_next_single(1) self.s2.on_completed() self.assertTrue(sink.is_completed) self.assertIsInstance(self.measure_state(obs), MergeStates.Stopped) self.assertIsInstance(self.measure_termination_state(obs), TerminationStates.BothCompletedState)
def test_left_complete(self): """ s1.on_completed NoneReceived -----------------> NoneReceived InitState LeftCompletedState """ sink = TObserver() obs = MergeObservable(self.s1, self.s2) obs.observe(init_observer_info(sink)) self.s1.on_completed() self.assertFalse(sink.is_completed) self.assertIsInstance(self.measure_state(obs), MergeStates.NoneReceived) self.assertIsInstance(self.measure_termination_state(obs), TerminationStates.LeftCompletedState)
def test_left_received_to_both_received_with_asynchronous_ack(self): """ s2.on_next LeftReceived ------------> BothReceivedContinueLeft """ sink = TObserver(immediate_continue=0) obs = MergeObservable(self.s1, self.s2) obs.observe(init_observer_info(sink)) self.s1.on_next_single(1) self.s1.on_next_single(1) right_ack = self.s2.on_next_single(2) self.assertIsInstance(self.measure_state(obs), MergeStates.BothReceivedContinueLeft) self.assertEqual(sink.received, [1]) self.assertFalse(right_ack.has_value)
def test_acknowledge_both_received(self): """ ack.on_next BothReceivedContinueLeft ------------> RightReceived """ sink = TObserver(immediate_continue=0) obs = MergeObservable(self.s1, self.s2) obs.observe(init_observer_info(sink)) self.s1.on_next_single(1) left_ack = self.s1.on_next_single(1) right_ack = self.s2.on_next_single(2) sink.ack.on_next(continue_ack) self.assertIsInstance(self.measure_state(obs), MergeStates.RightReceived) self.assertEqual(sink.received, [1, 1]) self.assertIsInstance(left_ack.value, ContinueAck) self.assertFalse(right_ack.has_value)
def unsafe_subscribe(self, subscriber: Subscriber): left_subscription = self._source.unsafe_subscribe(subscriber=subscriber) right_subscription = self._other.unsafe_subscribe(subscriber=subscriber) observable = MergeObservable(left=left_subscription.observable, right=right_subscription.observable) # # the base becomes anonymous after merging # base = None # info = BaseAndSelectors( # base=base, # ) return left_subscription.copy( observable=observable, )