| @@ -434,7 +434,7 @@ namespace Discord.Net.WebSockets | |||||
| var payload = (msg.Payload as JToken).ToObject<SessionDescriptionEvent>(_serializer); | var payload = (msg.Payload as JToken).ToObject<SessionDescriptionEvent>(_serializer); | ||||
| _secretKey = payload.SecretKey; | _secretKey = payload.SecretKey; | ||||
| SendSetSpeaking(true); | SendSetSpeaking(true); | ||||
| EndConnect(); | |||||
| await EndConnect(); | |||||
| } | } | ||||
| break; | break; | ||||
| case OpCodes.Speaking: | case OpCodes.Speaking: | ||||
| @@ -185,7 +185,7 @@ namespace Discord | |||||
| } | } | ||||
| catch (Exception ex) | catch (Exception ex) | ||||
| { | { | ||||
| _taskManager.SignalError(ex); | |||||
| await _taskManager.SignalError(ex); | |||||
| throw; | throw; | ||||
| } | } | ||||
| } | } | ||||
| @@ -100,7 +100,7 @@ namespace Discord.Net.WebSockets | |||||
| if (msg.Type == "READY" || msg.Type == "RESUMED") | if (msg.Type == "READY" || msg.Type == "RESUMED") | ||||
| { | { | ||||
| _reconnects = 0; | _reconnects = 0; | ||||
| EndConnect(); //Complete the connect | |||||
| await EndConnect(); //Complete the connect | |||||
| } | } | ||||
| } | } | ||||
| break; | break; | ||||
| @@ -86,20 +86,20 @@ namespace Discord.Net.WebSockets | |||||
| return TaskHelper.CompletedTask; | return TaskHelper.CompletedTask; | ||||
| } | } | ||||
| private void OnWebSocketError(object sender, ErrorEventArgs e) | |||||
| private async void OnWebSocketError(object sender, ErrorEventArgs e) | |||||
| { | { | ||||
| _taskManager.SignalError(e.Exception); | |||||
| await _taskManager.SignalError(e.Exception); | |||||
| _waitUntilConnect.Set(); | _waitUntilConnect.Set(); | ||||
| _waitUntilDisconnect.Set(); | _waitUntilDisconnect.Set(); | ||||
| } | } | ||||
| private void OnWebSocketClosed(object sender, EventArgs e) | |||||
| private async void OnWebSocketClosed(object sender, EventArgs e) | |||||
| { | { | ||||
| Exception ex; | Exception ex; | ||||
| if (e is ClosedEventArgs) | if (e is ClosedEventArgs) | ||||
| ex = new WebSocketException((e as ClosedEventArgs).Code, (e as ClosedEventArgs).Reason); | ex = new WebSocketException((e as ClosedEventArgs).Code, (e as ClosedEventArgs).Reason); | ||||
| else | else | ||||
| ex = new Exception("Connection lost"); | ex = new Exception("Connection lost"); | ||||
| _taskManager.SignalError(ex); | |||||
| await _taskManager.SignalError(ex); | |||||
| _waitUntilConnect.Set(); | _waitUntilConnect.Set(); | ||||
| _waitUntilDisconnect.Set(); | _waitUntilDisconnect.Set(); | ||||
| } | } | ||||
| @@ -91,11 +91,11 @@ namespace Discord.Net.WebSockets | |||||
| } | } | ||||
| catch (Exception ex) | catch (Exception ex) | ||||
| { | { | ||||
| _taskManager.SignalError(ex); | |||||
| await _taskManager.SignalError(ex); | |||||
| throw; | throw; | ||||
| } | } | ||||
| } | } | ||||
| protected void EndConnect() | |||||
| protected async Task EndConnect() | |||||
| { | { | ||||
| try | try | ||||
| { | { | ||||
| @@ -107,7 +107,7 @@ namespace Discord.Net.WebSockets | |||||
| } | } | ||||
| catch (Exception ex) | catch (Exception ex) | ||||
| { | { | ||||
| _taskManager.SignalError(ex); | |||||
| await _taskManager.SignalError(ex); | |||||
| } | } | ||||
| } | } | ||||
| @@ -67,14 +67,14 @@ namespace Discord | |||||
| //Signal the rest of the tasks to stop | //Signal the rest of the tasks to stop | ||||
| if (firstTask.Exception != null) | if (firstTask.Exception != null) | ||||
| SignalError(firstTask.Exception); | |||||
| await SignalError(firstTask.Exception); | |||||
| else | else | ||||
| SignalStop(); | |||||
| await SignalStop(); | |||||
| //Wait for the other tasks, and signal their errors too just in case | //Wait for the other tasks, and signal their errors too just in case | ||||
| try { await allTasks.ConfigureAwait(false); } | try { await allTasks.ConfigureAwait(false); } | ||||
| catch (AggregateException ex) { SignalError(ex.InnerExceptions.First()); } | |||||
| catch (Exception ex) { SignalError(ex); } | |||||
| catch (AggregateException ex) { await SignalError(ex.InnerExceptions.First()); } | |||||
| catch (Exception ex) { await SignalError(ex); } | |||||
| //Run the cleanup function within our lock | //Run the cleanup function within our lock | ||||
| if (_stopAction != null) | if (_stopAction != null) | ||||
| @@ -87,9 +87,9 @@ namespace Discord | |||||
| } | } | ||||
| } | } | ||||
| public void SignalStop(bool isExpected = false) | |||||
| public async Task SignalStop(bool isExpected = false) | |||||
| { | { | ||||
| using (_lock.Lock()) | |||||
| using (await _lock.LockAsync()) | |||||
| { | { | ||||
| if (isExpected) | if (isExpected) | ||||
| _wasStopExpected = true; | _wasStopExpected = true; | ||||
| @@ -119,9 +119,9 @@ namespace Discord | |||||
| await task; | await task; | ||||
| } | } | ||||
| public void SignalError(Exception ex) | |||||
| public async Task SignalError(Exception ex) | |||||
| { | { | ||||
| using (_lock.Lock()) | |||||
| using (await _lock.LockAsync()) | |||||
| { | { | ||||
| if (_stopReason != null) return; | if (_stopReason != null) return; | ||||