File tree 1 file changed +6
-0
lines changed
rxjava-core/src/main/java/rx/observers
1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -117,18 +117,23 @@ public void onNext(T t) {
117
117
queue = new FastList ();
118
118
}
119
119
queue .add (t != null ? t : NULL_SENTINEL );
120
+ // another thread is emitting so we add to the queue and return
120
121
return ;
121
122
}
123
+ // we can emit
122
124
emitting = true ;
125
+ // reference to the list to drain before emitting our value
123
126
list = queue ;
124
127
queue = null ;
125
128
}
126
129
130
+ // we only get here if we won the right to emit, otherwise we returned in the if(emitting) block above
127
131
try {
128
132
int iter = MAX_DRAIN_ITERATION ;
129
133
do {
130
134
drainQueue (list );
131
135
if (iter == MAX_DRAIN_ITERATION ) {
136
+ // after the first draining we emit our own value
132
137
actual .onNext (t );
133
138
}
134
139
--iter ;
@@ -152,6 +157,7 @@ public void onNext(T t) {
152
157
list = null ;
153
158
}
154
159
}
160
+ // this will only drain if terminated (done here outside of synchronized block)
155
161
drainQueue (list );
156
162
}
157
163
}
You can’t perform that action at this time.
0 commit comments