@@ -53,6 +53,13 @@ class BufferToggleSubscriber<T, O> extends Subscriber<T> {
53
53
}
54
54
55
55
_error ( err : any ) {
56
+ const contexts = this . contexts ;
57
+ while ( contexts . length > 0 ) {
58
+ const context = contexts . shift ( ) ;
59
+ context . subscription . unsubscribe ( ) ;
60
+ context . buffer = null ;
61
+ context . subscription = null ;
62
+ }
56
63
this . contexts = null ;
57
64
this . destination . error ( err ) ;
58
65
}
@@ -64,7 +71,9 @@ class BufferToggleSubscriber<T, O> extends Subscriber<T> {
64
71
this . destination . next ( context . buffer ) ;
65
72
context . subscription . unsubscribe ( ) ;
66
73
context . buffer = null ;
74
+ context . subscription = null ;
67
75
}
76
+ this . contexts = null ;
68
77
this . destination . complete ( ) ;
69
78
}
70
79
@@ -74,16 +83,14 @@ class BufferToggleSubscriber<T, O> extends Subscriber<T> {
74
83
75
84
let closingNotifier = tryCatch ( closingSelector ) ( value ) ;
76
85
if ( closingNotifier === errorObject ) {
77
- const err = closingNotifier . e ;
78
- this . contexts = null ;
79
- this . destination . error ( err ) ;
86
+ this . _error ( closingNotifier . e ) ;
80
87
} else {
81
88
let context = {
82
89
buffer : [ ] ,
83
90
subscription : new Subscription ( )
84
91
} ;
85
92
contexts . push ( context ) ;
86
- const subscriber = new BufferClosingNotifierSubscriber ( this , context ) ;
93
+ const subscriber = new BufferToggleClosingsSubscriber ( this , context ) ;
87
94
const subscription = closingNotifier . _subscribe ( subscriber ) ;
88
95
this . add ( context . subscription . add ( subscription ) ) ;
89
96
}
@@ -102,39 +109,40 @@ class BufferToggleSubscriber<T, O> extends Subscriber<T> {
102
109
}
103
110
}
104
111
105
- class BufferClosingNotifierSubscriber < T > extends Subscriber < T > {
106
- constructor ( private parent : BufferToggleSubscriber < any , T > , private context : { subscription : any , buffer : T [ ] } ) {
112
+ class BufferToggleOpeningsSubscriber < T > extends Subscriber < T > {
113
+ constructor ( private parent : BufferToggleSubscriber < any , T > ) {
107
114
super ( null ) ;
108
115
}
109
116
110
- _next ( ) {
111
- this . parent . closeBuffer ( this . context ) ;
117
+ _next ( value : T ) {
118
+ this . parent . openBuffer ( value ) ;
112
119
}
113
120
114
121
_error ( err ) {
115
122
this . parent . error ( err ) ;
116
123
}
117
124
118
125
_complete ( ) {
119
- this . parent . closeBuffer ( this . context ) ;
126
+ // noop
120
127
}
121
128
}
122
129
123
- class BufferToggleOpeningsSubscriber < T > extends Subscriber < T > {
124
- constructor ( private parent : BufferToggleSubscriber < any , T > ) {
130
+ class BufferToggleClosingsSubscriber < T > extends Subscriber < T > {
131
+ constructor ( private parent : BufferToggleSubscriber < any , T > ,
132
+ private context : { subscription : any , buffer : T [ ] } ) {
125
133
super ( null ) ;
126
134
}
127
135
128
- _next ( value : T ) {
129
- this . parent . openBuffer ( value ) ;
136
+ _next ( ) {
137
+ this . parent . closeBuffer ( this . context ) ;
130
138
}
131
139
132
140
_error ( err ) {
133
141
this . parent . error ( err ) ;
134
142
}
135
143
136
144
_complete ( ) {
137
- // noop
145
+ this . parent . closeBuffer ( this . context ) ;
138
146
}
139
147
}
140
148
0 commit comments