Skip to content

Commit

Permalink
refactor(mergeMap): use array instead of linked list
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath committed Sep 5, 2017
1 parent 13047b6 commit 6663883
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/operators/MergeMap.ts
Expand Up @@ -2,7 +2,7 @@
* Created by tushar on 31/08/17.
*/

import {LinkedList, LinkedListNode} from '../lib/LinkedList'
import {LinkedListNode} from '../lib/LinkedList'
import {IObservable} from '../lib/Observable'
import {IObserver} from '../lib/Observer'
import {IScheduler} from '../lib/Scheduler'
Expand Down Expand Up @@ -36,7 +36,7 @@ class MergeMapInnerObserver<T, S> implements IObserver<S> {

class MergeMapOuterObserver<T, S> implements IObserver<T> {
private __completed: boolean = false
private __buffer = new LinkedList<T>()
private __buffer: T[] = []

constructor(
readonly conc: number,
Expand All @@ -54,7 +54,7 @@ class MergeMapOuterObserver<T, S> implements IObserver<T> {
)
innerObserver.setup(node)
} else {
this.__buffer.add(val)
this.__buffer.push(val)
}
}

Expand All @@ -70,10 +70,8 @@ class MergeMapOuterObserver<T, S> implements IObserver<T> {
checkComplete() {
if (this.__completed && this.cSub.length() === 1) this.sink.complete()
else if (this.__buffer.length > 0) {
const head = this.__buffer.head()
if (head) {
this.__buffer.remove(head)
this.next(head.value)
if (this.__buffer.length > 0) {
this.next(this.__buffer.shift() as T)
}
}
}
Expand Down

0 comments on commit 6663883

Please sign in to comment.