forked from FarmMaps/FarmMapsApiClient
polling for task status.
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FarmmapsApi.HttpMessageHandlers;
|
||||
using FarmmapsApi.Models;
|
||||
using FarmmapsApi.Services;
|
||||
@@ -9,7 +12,8 @@ namespace FarmmapsApi
|
||||
{
|
||||
public static class Extensions
|
||||
{
|
||||
public static IServiceCollection AddFarmmapsServices(this IServiceCollection serviceCollection, Configuration configuration)
|
||||
public static IServiceCollection AddFarmmapsServices(this IServiceCollection serviceCollection,
|
||||
Configuration configuration)
|
||||
{
|
||||
return serviceCollection
|
||||
.AddSingleton(configuration)
|
||||
@@ -23,7 +27,26 @@ namespace FarmmapsApi
|
||||
.AddTransient<FarmmapsAuthenticationHandler>()
|
||||
.AddHttpClient<FarmmapsApiService>()
|
||||
.AddHttpMessageHandler<FarmmapsAuthenticationHandler>()
|
||||
.Services;;
|
||||
.Services;
|
||||
;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
} while (!token.IsCancellationRequested);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user