FarmMapsApiClient_WURtest/FarmmapsApi/Extensions.cs

27 lines
717 B
C#

using System;
using System.Threading;
using System.Threading.Tasks;
namespace FarmmapsApi
{
public static class Extensions
{
public static async Task PollTask(TimeSpan retryTime, Func<CancellationTokenSource, Task> callback)
{
var tokenSource = new CancellationTokenSource();
var token = tokenSource.Token;
do
{
try
{
await callback(tokenSource);
await Task.Delay(retryTime, token);
}
catch
{
tokenSource.Cancel();
}
} while (!token.IsCancellationRequested);
}
}
}