Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class ApiService : IApiService
{
readonly IClient _client;
readonly INetworkService _networkService;
public ApiService(IClient client, INetworkService networkService)
{
_client = client;
_networkService = networkService;
}
// No policies
public async Task<T> GetAsync<T>(Uri uri) where T : class
{
return await ProcessGetRequest<T>(uri);
}
// With policies
public async Task<T> GetAndRetry<T>(Uri uri, int retryCount, Func<Exception, int, Task> onRetry = null) where T : class
{
var func = new Func<Task<T>>(() => ProcessGetRequest<T>(uri));
return await _networkService.Retry<T>(func, retryCount, onRetry, cancelToken);
}
public async Task<T> GetWaitAndTry<T>(Uri uri, Func<int, TimeSpan> sleepDurationProvider, int retryCount, Func<Exception, TimeSpan, Task> onWaitAndRetry = null) where T : class
{
var func = new Func<Task<T>>(() => ProcessGetRequest<T>(uri));
return await _networkService.WaitAndRetry<T>(func, sleepDurationProvider, retryCount, onWaitAndRetry, cancellationToken);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.