btcpayserver/BTCPayServer.Rating/Providers/FallbackRateProvider.cs

39 lines
1.1 KiB
C#
Raw Normal View History

2020-06-28 21:44:35 -05:00
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
2018-05-03 03:32:42 +09:00
using BTCPayServer.Rating;
namespace BTCPayServer.Services.Rates
{
public class FallbackRateProvider : IRateProvider
{
readonly IRateProvider[] _Providers;
public FallbackRateProvider(IRateProvider[] providers)
{
if (providers == null)
throw new ArgumentNullException(nameof(providers));
_Providers = providers;
}
public async Task<PairRate[]> GetRatesAsync(CancellationToken cancellationToken)
{
foreach (var p in _Providers)
{
try
{
return await p.GetRatesAsync(cancellationToken).ConfigureAwait(false);
}
catch when (cancellationToken.IsCancellationRequested)
{
throw;
}
2020-06-28 17:55:27 +09:00
catch (Exception ex) { Exceptions.Add(ex); }
}
return Array.Empty<PairRate>();
}
2018-05-03 03:32:42 +09:00
public List<Exception> Exceptions { get; set; } = new List<Exception>();
}
}