1 | import { AsapAction } from './AsapAction';
|
---|
2 | import { AsapScheduler } from './AsapScheduler';
|
---|
3 |
|
---|
4 | /**
|
---|
5 | *
|
---|
6 | * Asap Scheduler
|
---|
7 | *
|
---|
8 | * <span class="informal">Perform task as fast as it can be performed asynchronously</span>
|
---|
9 | *
|
---|
10 | * `asap` scheduler behaves the same as {@link asyncScheduler} scheduler when you use it to delay task
|
---|
11 | * in time. If however you set delay to `0`, `asap` will wait for current synchronously executing
|
---|
12 | * code to end and then it will try to execute given task as fast as possible.
|
---|
13 | *
|
---|
14 | * `asap` scheduler will do its best to minimize time between end of currently executing code
|
---|
15 | * and start of scheduled task. This makes it best candidate for performing so called "deferring".
|
---|
16 | * Traditionally this was achieved by calling `setTimeout(deferredTask, 0)`, but that technique involves
|
---|
17 | * some (although minimal) unwanted delay.
|
---|
18 | *
|
---|
19 | * Note that using `asap` scheduler does not necessarily mean that your task will be first to process
|
---|
20 | * after currently executing code. In particular, if some task was also scheduled with `asap` before,
|
---|
21 | * that task will execute first. That being said, if you need to schedule task asynchronously, but
|
---|
22 | * as soon as possible, `asap` scheduler is your best bet.
|
---|
23 | *
|
---|
24 | * ## Example
|
---|
25 | * Compare async and asap scheduler<
|
---|
26 | * ```ts
|
---|
27 | * import { asapScheduler, asyncScheduler } from 'rxjs';
|
---|
28 | *
|
---|
29 | * asyncScheduler.schedule(() => console.log('async')); // scheduling 'async' first...
|
---|
30 | * asapScheduler.schedule(() => console.log('asap'));
|
---|
31 | *
|
---|
32 | * // Logs:
|
---|
33 | * // "asap"
|
---|
34 | * // "async"
|
---|
35 | * // ... but 'asap' goes first!
|
---|
36 | * ```
|
---|
37 | */
|
---|
38 | export const asapScheduler = new AsapScheduler(AsapAction);
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * @deprecated renamed. Use {@link asapScheduler}
|
---|
42 | */
|
---|
43 | export const asap = asapScheduler;
|
---|