Debian Codegraph @

node/rxjs/src/internal/util/executeSchedule.ts

raw
1 import { Subscription } from '../Subscription';
2 import { SchedulerAction, SchedulerLike } from '../types';
3
4 export function executeSchedule(
5 parentSubscription: Subscription,
6 scheduler: SchedulerLike,
7 work: () => void,
8 delay: number,
9 repeat: true
10 ): void;
11 export function executeSchedule(
12 parentSubscription: Subscription,
13 scheduler: SchedulerLike,
14 work: () => void,
15 delay?: number,
16 repeat?: false
17 ): Subscription;
18
19 export function executeSchedule(
20 parentSubscription: Subscription,
21 scheduler: SchedulerLike,
22 work: () => void,
23 delay = 0,
24 repeat = false
25 ): Subscription | void {
26 const scheduleSubscription = scheduler.schedule(function (this: SchedulerAction<any>) {
27 work();
28 if (repeat) {
29 parentSubscription.add(this.schedule(null, delay));
30 } else {
31 this.unsubscribe();
32 }
33 }, delay);
34
35 parentSubscription.add(scheduleSubscription);
36
37 if (!repeat) {
38 // Because user-land scheduler implementations are unlikely to properly reuse
39 // Actions for repeat scheduling, we can't trust that the returned subscription
40 // will control repeat subscription scenarios. So we're trying to avoid using them
41 // incorrectly within this library.
42 return scheduleSubscription;
43 }
44 }