Made TaskManager's Signal methods async

This commit is contained in:
RogueException
2016-01-02 01:54:25 -04:00
parent ee9045a12d
commit a49bf42552
6 changed files with 18 additions and 18 deletions

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:

View File

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

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;

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();
}

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);
}
}

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;