1from typing import Optional, Callable
2
3from rx import to_async
4from rx.core import Observable
5from rx.core.typing import Scheduler
6
7def _start(func: Callable, scheduler: Optional[Scheduler] = None) -> Observable:
8    """Invokes the specified function asynchronously on the specified
9    scheduler, surfacing the result through an observable sequence.
10
11    Example:
12        >>> res = rx.start(lambda: pprint('hello'))
13        >>> res = rx.start(lambda: pprint('hello'), rx.Scheduler.timeout)
14
15    Args:
16        func: Function to run asynchronously.
17        scheduler: [Optional] Scheduler to run the function on. If
18            not specified, defaults to Scheduler.timeout.
19
20    Remarks:
21        The function is called immediately, not during the subscription
22        of the resulting sequence. Multiple subscriptions to the
23        resulting sequence can observe the function's result.
24
25    Returns:
26        An observable sequence exposing the function's result value,
27        or an exception.
28    """
29
30    return to_async(func, scheduler)()
31