Skip to content

Commit 3c0553b

Browse files
demenskybenlesh
authored andcommitted
feat(scheduler): removed deprecated asyncScheduler constant
BREAKING CHANGE: The `async` constant is no longer available. Use `asyncScheduler`.
1 parent b7b9edf commit 3c0553b

File tree

11 files changed

+16
-21
lines changed

11 files changed

+16
-21
lines changed

docs_app/content/guide/scheduler.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<span class="informal">A Scheduler lets you define in what execution context will an Observable deliver notifications to its Observer.</span>
1010

11-
In the example below, we take the usual simple Observable that emits values `1`, `2`, `3` synchronously, and use the operator `observeOn` to specify the `async` scheduler to use for delivering those values.
11+
In the example below, we take the usual simple Observable that emits values `1`, `2`, `3` synchronously, and use the operator `observeOn` to specify the `asyncScheduler` scheduler to use for delivering those values.
1212

1313
<!-- prettier-ignore -->
1414
```ts
@@ -98,13 +98,13 @@ const proxyObserver = {
9898
};
9999
```
100100

101-
The `async` Scheduler operates with a `setTimeout` or `setInterval`, even if the given `delay` was zero. As usual, in JavaScript, `setTimeout(fn, 0)` is known to run the function `fn` earliest on the next event loop iteration. This explains why `got value 1` is delivered to the `finalObserver` after `just after subscribe` happened.
101+
The `asyncScheduler` Scheduler operates with a `setTimeout` or `setInterval`, even if the given `delay` was zero. As usual, in JavaScript, `setTimeout(fn, 0)` is known to run the function `fn` earliest on the next event loop iteration. This explains why `got value 1` is delivered to the `finalObserver` after `just after subscribe` happened.
102102

103103
The `schedule()` method of a Scheduler takes a `delay` argument, which refers to a quantity of time relative to the Scheduler's own internal clock. A Scheduler's clock need not have any relation to the actual wall-clock time. This is how temporal operators like `delay` operate not on actual time, but on time dictated by the Scheduler's clock. This is specially useful in testing, where a _virtual time Scheduler_ may be used to fake wall-clock time while in reality executing scheduled tasks synchronously.
104104

105105
## Scheduler Types
106106

107-
The `async` Scheduler is one of the built-in schedulers provided by RxJS. Each of these can be created and returned by using static properties of the `Scheduler` object.
107+
The `asyncScheduler` Scheduler is one of the built-in schedulers provided by RxJS. Each of these can be created and returned by using static properties of the `Scheduler` object.
108108

109109
| Scheduler | Purpose |
110110
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
@@ -116,7 +116,7 @@ The `async` Scheduler is one of the built-in schedulers provided by RxJS. Each o
116116

117117
## Using Schedulers
118118

119-
You may have already used schedulers in your RxJS code without explicitly stating the type of schedulers to be used. This is because all Observable operators that deal with concurrency have optional schedulers. If you do not provide the scheduler, RxJS will pick a default scheduler by using the principle of least concurrency. This means that the scheduler which introduces the least amount of concurrency that satisfies the needs of the operator is chosen. For example, for operators returning an observable with a finite and small number of messages, RxJS uses no Scheduler, i.e. `null` or `undefined`. For operators returning a potentially large or infinite number of messages, `queueScheduler` Scheduler is used. For operators which use timers, `async` is used.
119+
You may have already used schedulers in your RxJS code without explicitly stating the type of schedulers to be used. This is because all Observable operators that deal with concurrency have optional schedulers. If you do not provide the scheduler, RxJS will pick a default scheduler by using the principle of least concurrency. This means that the scheduler which introduces the least amount of concurrency that satisfies the needs of the operator is chosen. For example, for operators returning an observable with a finite and small number of messages, RxJS uses no Scheduler, i.e. `null` or `undefined`. For operators returning a potentially large or infinite number of messages, `queueScheduler` Scheduler is used. For operators which use timers, `asyncScheduler` is used.
120120

121121
Because RxJS uses the least concurrency scheduler, you can pick a different scheduler if you want to introduce concurrency for performance purpose. To specify a particular scheduler, you can use those operator methods that take a scheduler, e.g., `from([10, 20, 30], asyncScheduler)`.
122122

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export { AsyncSubject } from './internal/AsyncSubject';
2828

2929
/* Schedulers */
3030
export { asapScheduler } from './internal/scheduler/asap';
31-
export { async, asyncScheduler } from './internal/scheduler/async';
31+
export { asyncScheduler } from './internal/scheduler/async';
3232
export { queueScheduler } from './internal/scheduler/queue';
3333
export { animationFrameScheduler } from './internal/scheduler/animationFrame';
3434
export { VirtualTimeScheduler, VirtualAction } from './internal/scheduler/VirtualTimeScheduler';

src/internal/observable/generate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export function generate<T, S>(
136136
* `scheduler` property on the object passed to the operator. In both cases, a scheduler decides when
137137
* the next iteration of the loop will happen and therefore when the next value will be emitted
138138
* by the Observable. For example, to ensure that each value is pushed to the Observer
139-
* on a separate task in the event loop, you could use the `async` scheduler. Note that
139+
* on a separate task in the event loop, you could use the `asyncScheduler` scheduler. Note that
140140
* by default (when no scheduler is passed) values are simply emitted synchronously.
141141
*
142142
*

src/internal/observable/interval.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { timer } from './timer';
1515
* ascending integers, with a constant interval of time of your choosing
1616
* between those emissions. The first emission is not sent immediately, but
1717
* only after the first period has passed. By default, this operator uses the
18-
* `async` {@link SchedulerLike} to provide a notion of time, but you may pass any
18+
* `asyncScheduler` {@link SchedulerLike} to provide a notion of time, but you may pass any
1919
* {@link SchedulerLike} to it.
2020
*
2121
* ## Example
@@ -43,7 +43,7 @@ import { timer } from './timer';
4343
*
4444
* @param {number} [period=0] The interval size in milliseconds (by default)
4545
* or the time unit determined by the scheduler's clock.
46-
* @param {SchedulerLike} [scheduler=async] The {@link SchedulerLike} to use for scheduling
46+
* @param {SchedulerLike} [scheduler=asyncScheduler] The {@link SchedulerLike} to use for scheduling
4747
* the emission of values, and providing a notion of "time".
4848
* @return {Observable} An Observable that emits a sequential number each time
4949
* interval.

src/internal/observable/timer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Observable } from '../Observable';
22
import { SchedulerLike } from '../types';
3-
import { async as asyncScheduler } from '../scheduler/async';
3+
import { asyncScheduler } from '../scheduler/async';
44
import { isScheduler } from '../util/isScheduler';
55
import { isValidDate } from '../util/isDate';
66

src/internal/operators/auditTime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import { MonoTypeOperatorFunction, SchedulerLike } from '../types';
4545
* @param {number} duration Time to wait before emitting the most recent source
4646
* value, measured in milliseconds or the time unit determined internally
4747
* by the optional `scheduler`.
48-
* @param {SchedulerLike} [scheduler=async] The {@link SchedulerLike} to use for
48+
* @param {SchedulerLike} [scheduler=asyncScheduler] The {@link SchedulerLike} to use for
4949
* managing the timers that handle the rate-limiting behavior.
5050
* @return A function that returns an Observable that performs rate-limiting of
5151
* emissions from the source Observable.

src/internal/operators/debounceTime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import { createOperatorSubscriber } from './OperatorSubscriber';
5555
* unit determined internally by the optional `scheduler`) for the window of
5656
* time required to wait for emission silence before emitting the most recent
5757
* source value.
58-
* @param {SchedulerLike} [scheduler=async] The {@link SchedulerLike} to use for
58+
* @param {SchedulerLike} [scheduler=asyncScheduler] The {@link SchedulerLike} to use for
5959
* managing the timers that handle the timeout for each value.
6060
* @return A function that returns an Observable that delays the emissions of
6161
* the source Observable by the specified `dueTime`, and may drop some values

src/internal/operators/delay.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import { timer } from '../observable/timer';
5454
*
5555
* @param {number|Date} due The delay duration in milliseconds (a `number`) or
5656
* a `Date` until which the emission of the source items is delayed.
57-
* @param {SchedulerLike} [scheduler=async] The {@link SchedulerLike} to use for
57+
* @param {SchedulerLike} [scheduler=asyncScheduler] The {@link SchedulerLike} to use for
5858
* managing the timers that handle the time-shift for each item.
5959
* @return A function that returns an Observable that delays the emissions of
6060
* the source Observable by the specified timeout or Date.

src/internal/operators/sampleTime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import { interval } from '../observable/interval';
4040
*
4141
* @param {number} period The sampling period expressed in milliseconds or the
4242
* time unit determined internally by the optional `scheduler`.
43-
* @param {SchedulerLike} [scheduler=async] The {@link SchedulerLike} to use for
43+
* @param {SchedulerLike} [scheduler=asyncScheduler] The {@link SchedulerLike} to use for
4444
* managing the timers that handle the sampling.
4545
* @return A function that returns an Observable that emits the results of
4646
* sampling the values emitted by the source Observable at the specified time

src/internal/operators/timeoutWith.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { async } from '../scheduler/async';
1+
import { asyncScheduler } from '../scheduler/async';
22
import { isValidDate } from '../util/isDate';
33
import { ObservableInput, OperatorFunction, SchedulerLike } from '../types';
44
import { timeout } from './timeout';
@@ -88,7 +88,7 @@ export function timeoutWith<T, R>(
8888
let first: number | Date | undefined;
8989
let each: number | undefined;
9090
let _with: () => ObservableInput<R>;
91-
scheduler = scheduler ?? async;
91+
scheduler = scheduler ?? asyncScheduler;
9292

9393
if (isValidDate(due)) {
9494
first = due;

src/internal/scheduler/async.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { AsyncScheduler } from './AsyncScheduler';
77
*
88
* <span class="informal">Schedule task as if you used setTimeout(task, duration)</span>
99
*
10-
* `async` scheduler schedules tasks asynchronously, by putting them on the JavaScript
10+
* `asyncScheduler` scheduler schedules tasks asynchronously, by putting them on the JavaScript
1111
* event loop queue. It is best used to delay tasks in time or to schedule tasks repeating
1212
* in intervals.
1313
*
@@ -49,8 +49,3 @@ import { AsyncScheduler } from './AsyncScheduler';
4949
*/
5050

5151
export const asyncScheduler = new AsyncScheduler(AsyncAction);
52-
53-
/**
54-
* @deprecated Renamed to {@link asyncScheduler}. Will be removed in v8.
55-
*/
56-
export const async = asyncScheduler;

0 commit comments

Comments
 (0)