Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(race): support array of observables other than rest param #2548

Merged
merged 1 commit into from
May 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions spec/observables/race-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ describe('Observable.race', () => {
expectSubscriptions(e2.subscriptions).toBe(e2subs);
});

it('should race with array of observable', () => {
const e1 = cold('---a-----b-----c----|');
const e1subs = '^ !';
const e2 = cold('------x-----y-----z----|');
const e2subs = '^ !';
const expected = '---a-----b-----c----|';

const result = Observable.race([e1, e2]);

expectObservable(result).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
expectSubscriptions(e2.subscriptions).toBe(e2subs);
});

it('should race hot and hot', () => {
const e1 = hot('---a-----b-----c----|');
const e1subs = '^ !';
Expand Down
8 changes: 6 additions & 2 deletions src/operator/race.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import { InnerSubscriber } from '../InnerSubscriber';
import { subscribeToResult } from '../util/subscribeToResult';

/* tslint:disable:max-line-length */
export function race<T>(this: Observable<T>, observables: Array<Observable<T>>): Observable<T>;
export function race<T, R>(this: Observable<T>, observables: Array<Observable<T>>): Observable<R>;
export function race<T>(this: Observable<T>, ...observables: Array<Observable<T> | Array<Observable<T>>>): Observable<T>;
export function race<T, R>(this: Observable<T>, ...observables: Array<Observable<any> | Array<Observable<T>>>): Observable<R>;
export function race<T, R>(this: Observable<T>, ...observables: Array<Observable<any> | Array<Observable<any>>>): Observable<R>;
/* tslint:enable:max-line-length */

/**
Expand Down Expand Up @@ -39,10 +41,12 @@ export function race<T>(this: Observable<T>, ...observables: Array<Observable<T>
* @name race
* @owner Observable
*/
export function raceStatic<T>(observables: Array<Observable<T>>): Observable<T>;
export function raceStatic<T>(observables: Array<Observable<any>>): Observable<T>;
export function raceStatic<T>(...observables: Array<Observable<T> | Array<Observable<T>>>): Observable<T>;
export function raceStatic<T>(...observables: Array<Observable<any> | Array<Observable<any>>>): Observable<T> {
// if the only argument is an array, it was most likely called with
// `pair([obs1, obs2, ...])`
// `race([obs1, obs2, ...])`
if (observables.length === 1) {
if (isArray(observables[0])) {
observables = <Array<Observable<any>>>observables[0];
Expand Down