Files
jobtrackingapp/JobTrackerApi/Services/AiUsageExecutionScope.cs
T
cesnimda 25a6da951e
CI and Deploy / test (pull_request) Successful in 5m18s
CI and Deploy / deploy (pull_request) Has been skipped
fix(ai): meter synchronous generations
2026-08-15 20:25:10 +02:00

26 lines
656 B
C#

namespace JobTrackerApi.Services;
public sealed class AiUsageExecutionScope
{
private readonly AsyncLocal<int> _suppressionDepth = new();
public bool IsSuppressed => _suppressionDepth.Value > 0;
public IDisposable Suppress()
{
_suppressionDepth.Value++;
return new Restore(this);
}
private sealed class Restore(AiUsageExecutionScope owner) : IDisposable
{
private AiUsageExecutionScope? _owner = owner;
public void Dispose()
{
var current = Interlocked.Exchange(ref _owner, null);
if (current is not null) current._suppressionDepth.Value--;
}
}
}