mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-09 23:00:57 -05:00
game interface improvements
This commit is contained in:
@ -956,6 +956,19 @@ namespace SharedLibraryCore
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<T> WithWaitCancellation<T>(this Task<T> task,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var completedTask = await Task.WhenAny(task, Task.Delay(Timeout.Infinite, cancellationToken));
|
||||
if (completedTask == task)
|
||||
{
|
||||
return await task;
|
||||
}
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
throw new InvalidOperationException("Infinite delay task completed.");
|
||||
}
|
||||
|
||||
public static async Task<T> WithTimeout<T>(this Task<T> task, TimeSpan timeout)
|
||||
{
|
||||
await Task.WhenAny(task, Task.Delay(timeout));
|
||||
|
Reference in New Issue
Block a user