@@ -88,19 +88,21 @@ public void unsubscribe(final ParseQuery<T> query, final SubscriptionHandling su
88
88
89
89
@ Override
90
90
public void reconnect () {
91
- if (webSocketClient != null ) {
92
- webSocketClient .close ();
93
- }
94
- this .webSocketClient = webSocketClientFactory .createInstance (webSocketClientCallback , uri );
95
- this .webSocketClient .open ();
91
+ disconnectAsync ().continueWith (new Continuation <Void , Void >() {
92
+ @ Override
93
+ public Void then (Task <Void > task ) throws Exception {
94
+ webSocketClient = webSocketClientFactory .createInstance (webSocketClientCallback , uri );
95
+ webSocketClient .open ();
96
+ return null ;
97
+ }
98
+ });
96
99
userInitiatedDisconnect = false ;
97
100
}
98
101
99
102
@ Override
100
103
public void disconnect () {
101
104
if (webSocketClient != null ) {
102
- webSocketClient .close ();
103
- webSocketClient = null ;
105
+ disconnectAsync ();
104
106
userInitiatedDisconnect = true ;
105
107
}
106
108
}
@@ -131,6 +133,20 @@ public Void call() throws Exception {
131
133
}, taskExecutor );
132
134
}
133
135
136
+ private Task <Void > disconnectAsync () {
137
+ return Task .call (new Callable <Void >() {
138
+ @ Override
139
+ public Void call () throws Exception {
140
+ if (webSocketClient != null ) {
141
+ webSocketClient .close ();
142
+ webSocketClient = null ;
143
+ }
144
+
145
+ return null ;
146
+ }
147
+ }, taskExecutor );
148
+ }
149
+
134
150
private void parseMessage (String message ) throws LiveQueryException {
135
151
try {
136
152
JSONObject jsonObject = new JSONObject (message );
@@ -227,7 +243,7 @@ private void sendSubscription(final Subscription<T> subscription) {
227
243
public Void then (Task <String > task ) throws Exception {
228
244
String sessionToken = task .getResult ();
229
245
SubscribeClientOperation <T > op = new SubscribeClientOperation <>(subscription .getRequestId (), subscription .getQueryState (), sessionToken );
230
-
246
+
231
247
// dispatch errors
232
248
sendOperationAsync (op ).continueWith (new Continuation <Void , Void >() {
233
249
public Void then (Task <Void > task ) {
0 commit comments