Browse Source

Made TaskManager's Signal methods async

tags/docs-0.9
RogueException 9 years ago
parent
commit
a49bf42552
6 changed files with 18 additions and 18 deletions
  1. +1
    -1
      src/Discord.Net.Audio/Net/WebSockets/VoiceWebSocket.cs
  2. +1
    -1
      src/Discord.Net/DiscordClient.cs
  3. +1
    -1
      src/Discord.Net/Net/WebSockets/GatewaySocket.cs
  4. +4
    -4
      src/Discord.Net/Net/WebSockets/WS4NetEngine.cs
  5. +3
    -3
      src/Discord.Net/Net/WebSockets/WebSocket.cs
  6. +8
    -8
      src/Discord.Net/TaskManager.cs

+ 1
- 1
src/Discord.Net.Audio/Net/WebSockets/VoiceWebSocket.cs View File

@@ -434,7 +434,7 @@ namespace Discord.Net.WebSockets
var payload = (msg.Payload as JToken).ToObject<SessionDescriptionEvent>(_serializer);
_secretKey = payload.SecretKey;
SendSetSpeaking(true);
EndConnect();
await EndConnect();
}
break;
case OpCodes.Speaking:


+ 1
- 1
src/Discord.Net/DiscordClient.cs View File

@@ -185,7 +185,7 @@ namespace Discord
}
catch (Exception ex)
{
_taskManager.SignalError(ex);
await _taskManager.SignalError(ex);
throw;
}
}


+ 1
- 1
src/Discord.Net/Net/WebSockets/GatewaySocket.cs View File

@@ -100,7 +100,7 @@ namespace Discord.Net.WebSockets
if (msg.Type == "READY" || msg.Type == "RESUMED")
{
_reconnects = 0;
EndConnect(); //Complete the connect
await EndConnect(); //Complete the connect
}
}
break;


+ 4
- 4
src/Discord.Net/Net/WebSockets/WS4NetEngine.cs View File

@@ -86,20 +86,20 @@ namespace Discord.Net.WebSockets
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();
_waitUntilDisconnect.Set();
}
private void OnWebSocketClosed(object sender, EventArgs e)
private async void OnWebSocketClosed(object sender, EventArgs e)
{
Exception ex;
if (e is ClosedEventArgs)
ex = new WebSocketException((e as ClosedEventArgs).Code, (e as ClosedEventArgs).Reason);
else
ex = new Exception("Connection lost");
_taskManager.SignalError(ex);
await _taskManager.SignalError(ex);
_waitUntilConnect.Set();
_waitUntilDisconnect.Set();
}


+ 3
- 3
src/Discord.Net/Net/WebSockets/WebSocket.cs View File

@@ -91,11 +91,11 @@ namespace Discord.Net.WebSockets
}
catch (Exception ex)
{
_taskManager.SignalError(ex);
await _taskManager.SignalError(ex);
throw;
}
}
protected void EndConnect()
protected async Task EndConnect()
{
try
{
@@ -107,7 +107,7 @@ namespace Discord.Net.WebSockets
}
catch (Exception ex)
{
_taskManager.SignalError(ex);
await _taskManager.SignalError(ex);
}
}



+ 8
- 8
src/Discord.Net/TaskManager.cs View File

@@ -67,14 +67,14 @@ namespace Discord

//Signal the rest of the tasks to stop
if (firstTask.Exception != null)
SignalError(firstTask.Exception);
await SignalError(firstTask.Exception);
else
SignalStop();
await SignalStop();

//Wait for the other tasks, and signal their errors too just in case
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
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)
_wasStopExpected = true;
@@ -119,9 +119,9 @@ namespace Discord
await task;
}

public void SignalError(Exception ex)
public async Task SignalError(Exception ex)
{
using (_lock.Lock())
using (await _lock.LockAsync())
{
if (_stopReason != null) return;



Loading…
Cancel
Save