def __init__(self, *publishers: Publisher, map_: Callable[..., Any] = None, emit_on=None) -> None: MultiOperator.__init__(self, *publishers) # ._partial_state is a list keeping the latest emitted values from # each publisher. Stateless publishers will always keep the NONE entry # in this list. self._partial_state = [NONE for _ in publishers ] # type: MutableSequence[Any] # ._missing is keeping a set of source publishers which are required to # emit a value. This set starts with all source publishers. Stateful # publishers are required, stateless publishers not (will be removed # in .subscribe). self._missing = set(publishers) # ._index is a lookup table to get the list index based on publisher self._index = \ {p: i for i, p in enumerate(publishers) } # type: Dict[Publisher, int] # .emit_on is a set of publishers. When a source publisher is emitting # and is not in this set the CombineLatest will not emit a value. # If emit_on is None all the publishers will be in the set. if isinstance(emit_on, Publisher): self._emit_on = (emit_on, ) else: self._emit_on = emit_on self._map = map_
def subscribe(self, subscriber: 'Subscriber', prepend: bool = False) -> SubscriptionDisposable: disposable = MultiOperator.subscribe(self, subscriber, prepend) if self._missing: self._missing.clear() if self._state is NONE: Publisher.notify(self, self._init) else: Publisher.notify(self, self._state) return disposable
def unsubscribe(self, subscriber: Subscriber) -> None: MultiOperator.unsubscribe(self, subscriber) if not self._subscriptions: self._missing = set(self._orginators) self._partial_state[:] = [NONE for _ in self._partial_state]
def unsubscribe(self, subscriber: Subscriber) -> None: MultiOperator.unsubscribe(self, subscriber) if not self._subscriptions: self._missing.update(self._originators) self._state = NONE
def __init__(self, publisher_bit_mapping: Dict, init: int = 0) -> None: MultiOperator.__init__(self, *publisher_bit_mapping) self._init = init self._missing = set(self._originators) self._publisher_bit_mapping = publisher_bit_mapping