1 import { SchedulerAction, SchedulerLike } from '../types';
2 import { Observable } from '../Observable';
5 * Creates an Observable that emits a sequence of numbers within a specified
8 * <span class="informal">Emits a sequence of numbers in a range.</span>
12 * `range` operator emits a range of sequential integers, in order, where you
13 * select the `start` of the range and its `length`. By default, uses no
14 * {@link SchedulerLike} and just delivers the notifications synchronously, but may use
15 * an optional {@link SchedulerLike} to regulate those deliveries.
18 * Emits the numbers 1 to 10</caption>
20 * import { range } from 'rxjs';
22 * const numbers = range(1, 10);
23 * numbers.subscribe(x => console.log(x));
26 * @see {@link index/interval}
28 * @param {number} [start=0] The value of the first integer in the sequence.
29 * @param {number} count The number of sequential integers to generate.
30 * @param {SchedulerLike} [scheduler] A {@link SchedulerLike} to use for scheduling
31 * the emissions of the notifications.
32 * @return {Observable} An Observable of numbers that emits a finite range of
33 * sequential integers.
38 export function range(start: number = 0,
40 scheduler?: SchedulerLike): Observable<number> {
41 return new Observable<number>(subscriber => {
42 if (count === undefined) {
51 return scheduler.schedule(dispatch, 0, {
52 index, count, start, subscriber
56 if (index++ >= count) {
57 subscriber.complete();
60 subscriber.next(current++);
61 if (subscriber.closed) {
72 export function dispatch(this: SchedulerAction<any>, state: any) {
73 const { start, index, count, subscriber } = state;
76 subscriber.complete();
80 subscriber.next(start);
82 if (subscriber.closed) {
86 state.index = index + 1;
87 state.start = start + 1;