diff --git a/ATI.Services.Consul/ConsulServiceAddressCache.cs b/ATI.Services.Consul/ConsulServiceAddressCache.cs index 70ded29..d9cb057 100644 --- a/ATI.Services.Consul/ConsulServiceAddressCache.cs +++ b/ATI.Services.Consul/ConsulServiceAddressCache.cs @@ -23,8 +23,9 @@ public ConsulServiceAddressCache(string serviceName, string environment, TimeSpa _serviceName = serviceName; _environment = environment; _consulAdapter = new ConsulAdapter(); + _updateCacheTask = _consulAdapter.GetPassingServiceInstancesAsync(_serviceName, _environment); + _cachedServices = _updateCacheTask.GetAwaiter().GetResult(); _updateCacheTimer = new Timer(_ => ReloadCache(), null, ttl, ttl); - _cachedServices = _consulAdapter.GetPassingServiceInstancesAsync(serviceName, environment).GetAwaiter().GetResult(); } /// @@ -38,7 +39,7 @@ public ConsulServiceAddressCache(string serviceName, string environment, TimeSpa /// private void ReloadCache() { - if(_updateCacheTask.IsCompleted) + if(_updateCacheTask == null || _updateCacheTask.IsCompleted) _updateCacheTask = _consulAdapter.GetPassingServiceInstancesAsync(_serviceName, _environment); _cachedServices = _updateCacheTask.GetAwaiter().GetResult();