mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2026-01-08 08:34:25 +01:00
Enapsulating Token per code review discussions
This commit is contained in:
@@ -16,18 +16,23 @@ namespace BTCPayServer.HostedServices
|
||||
{
|
||||
public abstract class BaseAsyncService : IHostedService
|
||||
{
|
||||
protected CancellationTokenSource _Cts;
|
||||
private CancellationTokenSource _Cts;
|
||||
protected Task[] _Tasks;
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_Cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
|
||||
_Cts = new CancellationTokenSource();
|
||||
_Tasks = initializeTasks();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
internal abstract Task[] initializeTasks();
|
||||
|
||||
protected CancellationToken _SyncToken
|
||||
{
|
||||
get { return _Cts.Token; }
|
||||
}
|
||||
|
||||
protected async Task createLoopTask(Func<Task> act, [CallerMemberName]string caller = null)
|
||||
{
|
||||
await new SynchronizationContextRemover();
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace BTCPayServer.HostedServices
|
||||
var data = (await _SettingsRepository.GetSettingAsync<ThemeSettings>()) ?? new ThemeSettings();
|
||||
_CssThemeManager.Update(data);
|
||||
|
||||
await _SettingsRepository.WaitSettingsChanged<ThemeSettings>(_Cts.Token);
|
||||
await _SettingsRepository.WaitSettingsChanged<ThemeSettings>(_SyncToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace BTCPayServer.HostedServices
|
||||
.Exchanges
|
||||
.Select(c => (c.DisplayName, c.Name))
|
||||
.ToArray();
|
||||
await Task.Delay(TimeSpan.FromHours(5), _Cts.Token);
|
||||
await Task.Delay(TimeSpan.FromHours(5), _SyncToken);
|
||||
}
|
||||
|
||||
async Task RefreshCoinAverageSettings()
|
||||
@@ -61,7 +61,7 @@ namespace BTCPayServer.HostedServices
|
||||
{
|
||||
_coinAverageSettings.KeyPair = null;
|
||||
}
|
||||
await _SettingsRepository.WaitSettingsChanged<RatesSetting>(_Cts.Token);
|
||||
await _SettingsRepository.WaitSettingsChanged<RatesSetting>(_SyncToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user