Debian Codegraph @

node/rxjs/src/internal/scheduled/scheduled.ts

raw
1 import { scheduleObservable } from './scheduleObservable';
2 import { schedulePromise } from './schedulePromise';
3 import { scheduleArray } from './scheduleArray';
4 import { scheduleIterable } from './scheduleIterable';
5 import { scheduleAsyncIterable } from './scheduleAsyncIterable';
6 import { isInteropObservable } from '../util/isInteropObservable';
7 import { isPromise } from '../util/isPromise';
8 import { isArrayLike } from '../util/isArrayLike';
9 import { isIterable } from '../util/isIterable';
10 import { ObservableInput, SchedulerLike } from '../types';
11 import { Observable } from '../Observable';
12 import { isAsyncIterable } from '../util/isAsyncIterable';
13 import { createInvalidObservableTypeError } from '../util/throwUnobservableError';
14 import { isReadableStreamLike } from '../util/isReadableStreamLike';
15 import { scheduleReadableStreamLike } from './scheduleReadableStreamLike';
16
17 /**
18 * Converts from a common {@link ObservableInput} type to an observable where subscription and emissions
19 * are scheduled on the provided scheduler.
20 *
21 * @see {@link from}
22 * @see {@link of}
23 *
24 * @param input The observable, array, promise, iterable, etc you would like to schedule
25 * @param scheduler The scheduler to use to schedule the subscription and emissions from
26 * the returned observable.
27 */
28 export function scheduled<T>(input: ObservableInput<T>, scheduler: SchedulerLike): Observable<T> {
29 if (input != null) {
30 if (isInteropObservable(input)) {
31 return scheduleObservable(input, scheduler);
32 }
33 if (isArrayLike(input)) {
34 return scheduleArray(input, scheduler);
35 }
36 if (isPromise(input)) {
37 return schedulePromise(input, scheduler);
38 }
39 if (isAsyncIterable(input)) {
40 return scheduleAsyncIterable(input, scheduler);
41 }
42 if (isIterable(input)) {
43 return scheduleIterable(input, scheduler);
44 }
45 if (isReadableStreamLike(input)) {
46 return scheduleReadableStreamLike(input, scheduler);
47 }
48 }
49 throw createInvalidObservableTypeError(input);
50 }