import { SchedulerAction, SchedulerLike } from '../types'; import { Observable } from '../Observable'; /** * Creates an Observable that emits a sequence of numbers within a specified * range. * * <span class="informal">Emits a sequence of numbers in a range.</span> * *  * * `range` operator emits a range of sequential integers, in order, where you * select the `start` of the range and its `length`. By default, uses no * {@link SchedulerLike} and just delivers the notifications synchronously, but may use * an optional {@link SchedulerLike} to regulate those deliveries. * * ## Example * Emits the numbers 1 to 10</caption> * ```ts * import { range } from 'rxjs'; * * const numbers = range(1, 10); * numbers.subscribe(x => console.log(x)); * ``` * @see {@link timer} * @see {@link index/interval} * * @param {number} [start=0] The value of the first integer in the sequence. * @param {number} count The number of sequential integers to generate. * @param {SchedulerLike} [scheduler] A {@link SchedulerLike} to use for scheduling * the emissions of the notifications. * @return {Observable} An Observable of numbers that emits a finite range of * sequential integers. * @static true * @name range * @owner Observable */ export function range(start: number = 0, count?: number, scheduler?: SchedulerLike): Observable<number> { return new Observable<number>(subscriber => { if (count === undefined) { count = start; start = 0; } let index = 0; let current = start; if (scheduler) { return scheduler.schedule(dispatch, 0, { index, count, start, subscriber }); } else { do { if (index++ >= count) { subscriber.complete(); break; } subscriber.next(current++); if (subscriber.closed) { break; } } while (true); } return undefined; }); } /** @internal */ export function dispatch(this: SchedulerAction<any>, state: any) { const { start, index, count, subscriber } = state; if (index >= count) { subscriber.complete(); return; } subscriber.next(start); if (subscriber.closed) { return; } state.index = index + 1; state.start = start + 1; this.schedule(state); }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
dom | Folder | 0755 |
|
|
ConnectableObservable.ts | File | 5.42 KB | 0644 |
|
SubscribeOnObservable.ts | File | 1.59 KB | 0644 |
|
bindCallback.ts | File | 15.9 KB | 0644 |
|
bindNodeCallback.ts | File | 15.41 KB | 0644 |
|
combineLatest.ts | File | 21.95 KB | 0644 |
|
concat.ts | File | 9.43 KB | 0644 |
|
defer.ts | File | 2.53 KB | 0644 |
|
empty.ts | File | 2.21 KB | 0644 |
|
forkJoin.ts | File | 9.49 KB | 0644 |
|
from.ts | File | 3.06 KB | 0644 |
|
fromArray.ts | File | 423 B | 0644 |
|
fromEvent.ts | File | 10.38 KB | 0644 |
|
fromEventPattern.ts | File | 7.14 KB | 0644 |
|
fromIterable.ts | File | 511 B | 0644 |
|
fromObservable.ts | File | 485 B | 0644 |
|
fromPromise.ts | File | 439 B | 0644 |
|
generate.ts | File | 12.55 KB | 0644 |
|
iif.ts | File | 3.22 KB | 0644 |
|
interval.ts | File | 2.53 KB | 0644 |
|
merge.ts | File | 9.94 KB | 0644 |
|
never.ts | File | 1.16 KB | 0644 |
|
of.ts | File | 4.77 KB | 0644 |
|
onErrorResumeNext.ts | File | 3.83 KB | 0644 |
|
pairs.ts | File | 3.06 KB | 0644 |
|
partition.ts | File | 2.61 KB | 0644 |
|
race.ts | File | 5.03 KB | 0644 |
|
range.ts | File | 2.28 KB | 0644 |
|
throwError.ts | File | 2.2 KB | 0644 |
|
timer.ts | File | 3.32 KB | 0644 |
|
using.ts | File | 3.04 KB | 0644 |
|
zip.ts | File | 12.06 KB | 0644 |
|