File: _observeon.py

package info (click to toggle)
python-rx 4.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,204 kB
  • sloc: python: 39,525; javascript: 77; makefile: 24
file content (43 lines) | stat: -rw-r--r-- 1,212 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from typing import Callable, Optional, TypeVar

from reactivex import Observable, abc
from reactivex.observer import ObserveOnObserver

_T = TypeVar("_T")


def observe_on_(
    scheduler: abc.SchedulerBase,
) -> Callable[[Observable[_T]], Observable[_T]]:
    def observe_on(source: Observable[_T]) -> Observable[_T]:
        """Wraps the source sequence in order to run its observer
        callbacks on the specified scheduler.

        This only invokes observer callbacks on a scheduler. In case
        the subscription and/or unsubscription actions have
        side-effects that require to be run on a scheduler, use
        subscribe_on.

        Args:
            source: Source observable.


        Returns:
            Returns the source sequence whose observations happen on
            the specified scheduler.
        """

        def subscribe(
            observer: abc.ObserverBase[_T],
            subscribe_scheduler: Optional[abc.SchedulerBase] = None,
        ):
            return source.subscribe(
                ObserveOnObserver(scheduler, observer), scheduler=subscribe_scheduler
            )

        return Observable(subscribe)

    return observe_on


__all__ = ["observe_on_"]