RemoteItemMover, Startup/Exit handler refactor

This commit is contained in:
2023-07-26 13:51:17 +02:00
parent 3de71cbdbe
commit 0b36fb939c
23 changed files with 210 additions and 110 deletions

View File

@@ -2,15 +2,20 @@ namespace FileTime.Core.Extensions;
public static class TaskExtensions
{
public static async Task<T?> AwaitWithTimeout<T>(this Task<T> task, int timeout, T? defaultValue = default)
public static async Task TimeoutAfter(this Task task, int timeoutInMilliseconds)
{
if (await Task.WhenAny(task, Task.Delay(timeout)) == task)
if (await Task.WhenAny(task, Task.Delay(timeoutInMilliseconds)) != task)
throw new TimeoutException();
}
public static async Task<T?> TimeoutAfter<T>(this Task<T> task, int timeoutInMilliseconds, T? defaultValue = default)
{
if (await Task.WhenAny(task, Task.Delay(timeoutInMilliseconds)) == task)
{
return task.Result;
return await task;
}
else
{
return defaultValue;
throw new TimeoutException();
}
}
}