|
41 | 41 | this.error = null; |
42 | 42 | this.hasFailed = false; |
43 | 43 | this.hasCompleted = false; |
44 | | - this.controlledDisposable = disposableEmpty; |
45 | 44 | } |
46 | 45 |
|
47 | 46 | addProperties(ControlledSubject.prototype, Observer, { |
48 | 47 | onCompleted: function () { |
49 | 48 | this.hasCompleted = true; |
50 | | - (!this.enableQueue || this.queue.length === 0) && this.subject.onCompleted(); |
| 49 | + if (!this.enableQueue || this.queue.length === 0) |
| 50 | + this.subject.onCompleted(); |
| 51 | + else |
| 52 | + this.queue.push(Rx.Notification.createOnCompleted()); |
| 53 | + //(!this.enableQueue || this.queue.length === 0) && this.subject.onCompleted(); |
51 | 54 | }, |
52 | 55 | onError: function (error) { |
53 | 56 | this.hasFailed = true; |
54 | 57 | this.error = error; |
55 | | - (!this.enableQueue || this.queue.length === 0) && this.subject.onError(error); |
| 58 | + if (!this.enableQueue || this.queue.length === 0) |
| 59 | + this.subject.onError(error); |
| 60 | + else |
| 61 | + this.queue.push(Rx.Notification.createOnError(error)); |
| 62 | + //(!this.enableQueue || this.queue.length === 0) && this.subject.onError(error); |
56 | 63 | }, |
57 | 64 | onNext: function (value) { |
58 | 65 | var hasRequested = false; |
59 | 66 |
|
60 | 67 | if (this.requestedCount === 0) { |
61 | | - this.enableQueue && this.queue.push(value); |
| 68 | + this.enableQueue && this.queue.push(Rx.Notification.createOnNext(value)); |
62 | 69 | } else { |
63 | 70 | (this.requestedCount !== -1 && this.requestedCount-- === 0) && this.disposeCurrentRequest(); |
64 | 71 | hasRequested = true; |
|
67 | 74 | }, |
68 | 75 | _processRequest: function (numberOfItems) { |
69 | 76 | if (this.enableQueue) { |
70 | | - while (this.queue.length >= numberOfItems && numberOfItems > 0) { |
71 | | - this.subject.onNext(this.queue.shift()); |
72 | | - numberOfItems--; |
| 77 | + //while (this.queue.length >= numberOfItems && numberOfItems > 0) { |
| 78 | + // this.subject.onNext(this.queue.shift()); |
| 79 | + // numberOfItems--; |
| 80 | + //} |
| 81 | + |
| 82 | + while ((this.queue.length > 0 && this.queue[0].kind !== 'N') || (this.queue.length >= numberOfItems && numberOfItems > 0)) { |
| 83 | + var first = this.queue.shift(); |
| 84 | + first.accept(this.subject); |
| 85 | + if (first.kind === 'N') numberOfItems--; |
| 86 | + else { this.disposeCurrentRequest(); this.queue = []; } |
73 | 87 | } |
74 | 88 |
|
75 | 89 | return this.queue.length !== 0 ? |
|
79 | 93 |
|
80 | 94 | if (this.hasFailed) { |
81 | 95 | this.subject.onError(this.error); |
82 | | - this.controlledDisposable.dispose(); |
83 | | - this.controlledDisposable = disposableEmpty; |
84 | 96 | } else if (this.hasCompleted) { |
85 | 97 | this.subject.onCompleted(); |
86 | | - this.controlledDisposable.dispose(); |
87 | | - this.controlledDisposable = disposableEmpty; |
88 | 98 | } |
89 | 99 |
|
90 | 100 | return { numberOfItems: numberOfItems, returnValue: false }; |
|
0 commit comments