stockData))); //#A async Task <Tuple <string, StockData[]> > ProcessStockHistoryRetry(string symbol) { string stockHistory = await AsyncEx.Retry(() => DownloadStockHistory(symbol), 5, TimeSpan.FromSeconds(2)); StockData[] stockData = await ConvertStockHistory(stockHistory); return(Tuple.Create(symbol, stockData)); }
async Task <Tuple <string, StockData[]> > ProcessStockHistoryComplete(string symbol) { var stockData = await AsyncEx.Retry(() => DownloadStockHistory(symbol) .OrElse(() => StreamReadStockHistory(symbol)) .Bind(stockHistory => ConvertStockHistory(stockHistory)), 3, TimeSpan.FromSeconds(1)); return(Tuple.Create(symbol, stockData)); }
static async Task RunDownloadImageWithRetry() { // DEMO 6.2 // Combinator Retry/otherwise Image image = await AsyncEx.Retry(async() => await DownloadImageAsync("Bugghina001.jpg") .Otherwise(async() => await DownloadImageAsync("Bugghina002.jpg")), 5, TimeSpan.FromSeconds(2)); ProcessImage(image); }
async Task <Tuple <string, StockData[]> > ProcessStockHistoryConditional(string symbol) { Func <Func <string, string>, Func <string, Task <string> > > downloadStock = service => stock => DownloadStockHistory(service, stock); // #C Func <string, Task <string> > googleService = downloadStock(googleSourceUrl); // #D Func <string, Task <string> > yahooService = downloadStock(yahooSourceUrl); // #D return(await AsyncEx.Retry( // #E () => googleService(symbol).Otherwise(() => yahooService(symbol)), //#F 5, TimeSpan.FromSeconds(2)) .Bind(data => ConvertStockHistory(data)) // #G .Map(prices => Tuple.Create(symbol, prices))); // #H }
private async Task <IEnumerable <AlbumTracksSearchEntry> > GetAllMusicTracksInternal(string searchString, CancellationToken token) { _logger.LogInformation(searchString); var client = new RestClient($"https://itunes.apple.com/lookup?id={searchString}&entity=song"); var request = new RestRequest(Method.GET); IRestResponse response = await AsyncEx.Retry(() => client.ExecuteAsync(request, token), 3, TimeSpan.FromMilliseconds(100), token); var searchResponse = JsonConvert.DeserializeObject <ApiResponse <AlbumTracksSearchEntry> >(response.Content); await _cachingProvider.SetAsync(searchString, searchResponse.Results, TimeSpan.FromMinutes(ExpirationCacheInMinutes)); return(searchResponse.Results.Where(x => x.TrackId != null)); }