1 | import { AsyncScheduler } from './AsyncScheduler';
|
---|
2 | /**
|
---|
3 | *
|
---|
4 | * Async Scheduler
|
---|
5 | *
|
---|
6 | * <span class="informal">Schedule task as if you used setTimeout(task, duration)</span>
|
---|
7 | *
|
---|
8 | * `async` scheduler schedules tasks asynchronously, by putting them on the JavaScript
|
---|
9 | * event loop queue. It is best used to delay tasks in time or to schedule tasks repeating
|
---|
10 | * in intervals.
|
---|
11 | *
|
---|
12 | * If you just want to "defer" task, that is to perform it right after currently
|
---|
13 | * executing synchronous code ends (commonly achieved by `setTimeout(deferredTask, 0)`),
|
---|
14 | * better choice will be the {@link asapScheduler} scheduler.
|
---|
15 | *
|
---|
16 | * ## Examples
|
---|
17 | * Use async scheduler to delay task
|
---|
18 | * ```ts
|
---|
19 | * import { asyncScheduler } from 'rxjs';
|
---|
20 | *
|
---|
21 | * const task = () => console.log('it works!');
|
---|
22 | *
|
---|
23 | * asyncScheduler.schedule(task, 2000);
|
---|
24 | *
|
---|
25 | * // After 2 seconds logs:
|
---|
26 | * // "it works!"
|
---|
27 | * ```
|
---|
28 | *
|
---|
29 | * Use async scheduler to repeat task in intervals
|
---|
30 | * ```ts
|
---|
31 | * import { asyncScheduler } from 'rxjs';
|
---|
32 | *
|
---|
33 | * function task(state) {
|
---|
34 | * console.log(state);
|
---|
35 | * this.schedule(state + 1, 1000); // `this` references currently executing Action,
|
---|
36 | * // which we reschedule with new state and delay
|
---|
37 | * }
|
---|
38 | *
|
---|
39 | * asyncScheduler.schedule(task, 3000, 0);
|
---|
40 | *
|
---|
41 | * // Logs:
|
---|
42 | * // 0 after 3s
|
---|
43 | * // 1 after 4s
|
---|
44 | * // 2 after 5s
|
---|
45 | * // 3 after 6s
|
---|
46 | * ```
|
---|
47 | */
|
---|
48 | export declare const asyncScheduler: AsyncScheduler;
|
---|
49 | /**
|
---|
50 | * @deprecated renamed. Use {@link asyncScheduler}
|
---|
51 | */
|
---|
52 | export declare const async: AsyncScheduler;
|
---|