Select item upon entering container
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
namespace FileTime.Core.Extensions;
|
||||
|
||||
public static class TaskExtensions
|
||||
{
|
||||
public static async Task<T?> AwaitWithTimeout<T>(this Task<T> task, int timeout, T? defaultValue = default)
|
||||
{
|
||||
if (await Task.WhenAny(task, Task.Delay(timeout)) == task)
|
||||
{
|
||||
return task.Result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user