private async Task RefreshCacheAsync()

in aliyun-net-credentials/Provider/RefreshCachedSupplier.cs [254:293]


        private async Task RefreshCacheAsync()
        {
            var lockTaken = false;
            try
            {
                lockTaken = await refreshLockAsync.WaitAsync(RefreshBlockingMaxWait);

                if (lockTaken && (CacheIsStale() || ShouldInitiateCachePrefetch()))
                {
                    try
                    {
                        this.cachedValue = HandleFetchedSuccess(await refreshFuncAsync());
                    }
                    catch (Exception ex)
                    {
                        this.cachedValue = HandleFetchedFailure(ex);
                    }
                }
            }
            catch (ThreadInterruptedException)
            {
                Thread.CurrentThread.Interrupt();
                throw new InvalidOperationException("Interrupted waiting to refresh the value.");
            }
            catch (CredentialException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new CredentialException("Failed to refresh credentials.", ex.Message);
            }
            finally
            {
                if (lockTaken)
                {
                    refreshLockAsync.Release();
                }
            }
        }