Skip to content

Commit

Permalink
async await
Browse files Browse the repository at this point in the history
  • Loading branch information
muphblu committed Nov 14, 2023
1 parent 5184904 commit da8bd5b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ATI.Services.Consul/ConsulServiceAddressCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/// <summary>
Expand All @@ -42,12 +45,12 @@ public ConsulServiceAddressCache(string serviceName,
/// <summary>
/// Запускает таску на обновление кеша
/// </summary>
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()
Expand Down

0 comments on commit da8bd5b

Please sign in to comment.