-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(merge): fix issues with async in merge
- moves support types from merge-support to mergeAll-support - fixes strange issues with async - adds virtual time tests for merge and mergeAll
- Loading branch information
Showing
7 changed files
with
84 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import Observable from '../Observable'; | ||
import mergeStatic from './merge-static'; | ||
import Scheduler from '../Scheduler'; | ||
|
||
export default function merge<R>(...observables: (Observable<any>|number)[]): Observable<R> { | ||
export default function merge<R>(...observables: (Observable<any>|Scheduler|number)[]): Observable<R> { | ||
observables.unshift(this); | ||
return mergeStatic.apply(this, observables); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import Observable from '../Observable'; | ||
import Operator from '../Operator'; | ||
import Subscriber from '../Subscriber'; | ||
import Observer from '../Observer'; | ||
import Subscription from '../Subscription'; | ||
|
||
export class MergeAllOperator<T, R> implements Operator<T, R> { | ||
constructor(private concurrent: number) { | ||
|
||
} | ||
|
||
call(observer: Observer<T>) { | ||
return new MergeAllSubscriber(observer, this.concurrent); | ||
} | ||
} | ||
|
||
export class MergeAllSubscriber<T> extends Subscriber<T> { | ||
private hasCompleted: boolean = false; | ||
private buffer: Observable<any>[] = []; | ||
private active: number = 0; | ||
constructor(destination: Observer<T>, private concurrent:number) { | ||
super(destination); | ||
} | ||
|
||
_next(observable: any) { | ||
if(this.active < this.concurrent) { | ||
if(observable._isScalar) { | ||
this.destination.next(observable.value); | ||
} else { | ||
const innerSub = new Subscription(); | ||
this.add(innerSub); | ||
this.active++; | ||
innerSub.add(observable.subscribe(new MergeAllInnerSubscriber(this.destination, this, innerSub))); | ||
} | ||
} else { | ||
this.buffer.push(observable); | ||
} | ||
} | ||
|
||
_complete() { | ||
this.hasCompleted = true; | ||
if(this.active === 0 && this.buffer.length === 0) { | ||
this.destination.complete(); | ||
} | ||
} | ||
|
||
notifyComplete(innerSub: Subscription<T>) { | ||
const buffer = this.buffer; | ||
this.remove(innerSub); | ||
this.active--; | ||
if(buffer.length > 0) { | ||
this._next(buffer.shift()); | ||
} else if (this.active === 0 && this.hasCompleted) { | ||
this.destination.complete(); | ||
} | ||
} | ||
} | ||
|
||
export class MergeAllInnerSubscriber<T> extends Subscriber<T> { | ||
constructor(destination: Observer<T>, private parent: MergeAllSubscriber<T>, | ||
private innerSub: Subscription<T> ) { | ||
super(destination); | ||
} | ||
|
||
_complete() { | ||
this.parent.notifyComplete(this.innerSub); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters