From da8bd5bf0a6ae58b7d7c3ee3c36af15a0902359c Mon Sep 17 00:00:00 2001 From: Aidar Shaikhiev Date: Tue, 14 Nov 2023 15:53:28 +0600 Subject: [PATCH] async await --- ATI.Services.Consul/ConsulServiceAddressCache.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ATI.Services.Consul/ConsulServiceAddressCache.cs b/ATI.Services.Consul/ConsulServiceAddressCache.cs index 59c97fb..5b448d1 100644 --- a/ATI.Services.Consul/ConsulServiceAddressCache.cs +++ b/ATI.Services.Consul/ConsulServiceAddressCache.cs @@ -30,7 +30,10 @@ public ConsulServiceAddressCache(string serviceName, _consulAdapter = new ConsulAdapter(); _updateCacheTask = _consulAdapter.GetPassingServiceInstancesAsync(_serviceName, _environment, passingOnly); _cachedServices = _updateCacheTask.GetAwaiter().GetResult(); + + #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed _updateCacheTimer = new Timer(_ => ReloadCache(), null, ttl, ttl); + #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed } /// @@ -42,12 +45,12 @@ public ConsulServiceAddressCache(string serviceName, /// /// Запускает таску на обновление кеша /// - private void ReloadCache() + private async Task ReloadCache() { if(_updateCacheTask == null || _updateCacheTask.IsCompleted) _updateCacheTask = _consulAdapter.GetPassingServiceInstancesAsync(_serviceName, _environment, _passingOnly); - _cachedServices = _updateCacheTask.GetAwaiter().GetResult(); + _cachedServices = await _updateCacheTask; } public void Dispose()