Skip to content

Instantly share code, notes, and snippets.

@hnabbasi
Last active July 11, 2018 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hnabbasi/5f62fdf98f6f9d9e6a7053fdc1371e99 to your computer and use it in GitHub Desktop.
Save hnabbasi/5f62fdf98f6f9d9e6a7053fdc1371e99 to your computer and use it in GitHub Desktop.
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