This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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