Cleaned up TaskHelper
This commit is contained in:
@@ -34,28 +34,32 @@ namespace Discord.Helpers
|
|||||||
else
|
else
|
||||||
return await self.ConfigureAwait(false);
|
return await self.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
public static async Task Timeout(this Task self, int milliseconds, CancellationTokenSource cancelToken)
|
public static async Task Timeout(this Task self, int milliseconds, CancellationTokenSource timeoutToken)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
cancelToken.CancelAfter(milliseconds);
|
timeoutToken.CancelAfter(milliseconds);
|
||||||
await self;
|
await self.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
{
|
{
|
||||||
throw new TimeoutException();
|
if (timeoutToken.IsCancellationRequested)
|
||||||
|
throw new TimeoutException();
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static async Task<T> Timeout<T>(this Task<T> self, int milliseconds, CancellationTokenSource cancelToken)
|
public static async Task<T> Timeout<T>(this Task<T> self, int milliseconds, CancellationTokenSource timeoutToken)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
cancelToken.CancelAfter(milliseconds);
|
timeoutToken.CancelAfter(milliseconds);
|
||||||
return await self;
|
return await self.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
{
|
{
|
||||||
throw new TimeoutException();
|
if (timeoutToken.IsCancellationRequested)
|
||||||
|
throw new TimeoutException();
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user