@@ -117,7 +117,9 @@ public void unsubscribe() {
117
117
// room for the next worker in the workerQueue.
118
118
if (unsubscribed .compareAndSet (false , true )) {
119
119
actualWorker .unsubscribe ();
120
- actionQueue .onCompleted ();
120
+ synchronized (actionQueue ) {
121
+ actionQueue .onCompleted ();
122
+ }
121
123
}
122
124
}
123
125
@@ -130,21 +132,27 @@ public boolean isUnsubscribed() {
130
132
public Subscription schedule (final Action0 action , final long delayTime , final TimeUnit unit ) {
131
133
// send a scheduled action to the actionQueue
132
134
DelayedAction delayedAction = new DelayedAction (action , delayTime , unit );
133
- actionQueue .onNext (delayedAction );
135
+ synchronized (actionQueue ) {
136
+ actionQueue .onNext (delayedAction );
137
+ }
134
138
return delayedAction ;
135
139
}
136
140
137
141
@ Override
138
142
public Subscription schedule (final Action0 action ) {
139
143
// send a scheduled action to the actionQueue
140
144
ImmediateAction immediateAction = new ImmediateAction (action );
141
- actionQueue .onNext (immediateAction );
145
+ synchronized (actionQueue ) {
146
+ actionQueue .onNext (immediateAction );
147
+ }
142
148
return immediateAction ;
143
149
}
144
150
};
145
151
146
152
// enqueue the completable that process actions put in reply subject
147
- workerQueue .onNext (actions );
153
+ synchronized (workerQueue ) {
154
+ workerQueue .onNext (actions );
155
+ }
148
156
149
157
// return the worker that adds actions to the reply subject
150
158
return worker ;
0 commit comments