in aliyun-net-credentials/Policy/NonBlocking.cs [65:107]
public async Task PrefetchAsync(Func<Task> valueUpdater)
{
if (Interlocked.CompareExchange(ref currentlyRefreshing, 1, 0) != 0)
{
return;
}
// 判断是否存在可用的资源
if (!await concurrentRefreshLeases.WaitAsync(0))
{
Logger.Warn("Skipping a background refresh task because there are too many other tasks running.");
// 将状态重置为 false
Interlocked.Exchange(ref currentlyRefreshing, 0);
return;
}
try
{
Task.Run(async () =>
{
try
{
await valueUpdater.Invoke();
}
catch (Exception ex)
{
Logger.Warn(ex.Message);
throw;
}
finally
{
concurrentRefreshLeases.Release();
Interlocked.Exchange(ref currentlyRefreshing, 0);
}
});
}
catch (Exception ex)
{
Logger.Warn(ex.Message);
concurrentRefreshLeases.Release();
Interlocked.Exchange(ref currentlyRefreshing, 0);
throw;
}
}