in aliyun-net-credentials/Policy/NonBlocking.cs [20:63]
public void Prefetch(Action valueUpdater)
{
if (Interlocked.CompareExchange(ref currentlyRefreshing, 1, 0) != 0)
{
return;
}
// 判断是否存在可用的资源
if (!concurrentRefreshLeases.Wait(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(() =>
{
try
{
valueUpdater.Invoke();
}
catch (Exception ex)
{
Logger.Warn(ex.Message);
throw;
}
finally
{
concurrentRefreshLeases.Release();
Interlocked.Exchange(ref currentlyRefreshing, 0);
}
});
}
catch (Exception ex)
{
concurrentRefreshLeases.Release();
Interlocked.Exchange(ref currentlyRefreshing, 0);
Logger.Warn(ex.Message);
throw;
}
}