Enapsulating Token per code review discussions

This commit is contained in:
lepipele
2018-04-26 21:44:21 -05:00
parent 2e5d29064b
commit fbc4ca89aa
3 changed files with 10 additions and 5 deletions

View File

@@ -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();

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}