Ejemplo n.º 1
0
    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_
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
 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]
Ejemplo n.º 4
0
 def unsubscribe(self, subscriber: Subscriber) -> None:
     MultiOperator.unsubscribe(self, subscriber)
     if not self._subscriptions:
         self._missing.update(self._originators)
         self._state = NONE
Ejemplo n.º 5
0
    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