Skip to content

Commit

Permalink
fix(range): Range should be same for every subscriber (#3707)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbonnet authored and benlesh committed May 21, 2018
1 parent 682b39d commit 9642133
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 15 additions & 0 deletions spec/observables/range-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ describe('range', () => {
expectObservable(e1).toBe(expected, values);
});

it('should work for two subscribers', () => {
const e1 = range(1, 5)
.concatMap((x, i) => Observable.of(x).delay(i === 0 ? 0 : 20, rxTestScheduler));
const expected = 'a-b-c-d-(e|)';
const values = {
a: 1,
b: 2,
c: 3,
d: 4,
e: 5
};
expectObservable(e1).toBe(expected, values);
expectObservable(e1).toBe(expected, values);
});

it('should synchronously create a range of values by default', () => {
const results = [] as any[];
range(12, 4).subscribe(function (x) {
Expand Down
3 changes: 2 additions & 1 deletion src/internal/observable/range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export function range(start: number = 0,
scheduler?: SchedulerLike): Observable<number> {
return new Observable<number>(subscriber => {
let index = 0;
let current = start;

if (scheduler) {
return scheduler.schedule(dispatch, 0, {
Expand All @@ -47,7 +48,7 @@ export function range(start: number = 0,
subscriber.complete();
break;
}
subscriber.next(start++);
subscriber.next(current++);
if (subscriber.closed) {
break;
}
Expand Down

0 comments on commit 9642133

Please sign in to comment.