fix throttle ext

fix configs
fix build scripts
This commit is contained in:
Alex Bezdieniezhnykh
2025-04-17 19:40:09 +03:00
parent 277aaf09b0
commit d42409de7d
9 changed files with 21 additions and 61 deletions
@@ -6,7 +6,7 @@ public static class ThrottleExt
{
private class ThrottleState(Func<Task> action)
{
public Func<Task> Action { get; } = action ?? throw new ArgumentNullException(nameof(action));
public Func<Task> Action { get; set; } = action ?? throw new ArgumentNullException(nameof(action));
public bool IsCoolingDown = false;
public bool CallScheduledDuringCooldown = false;
public Task CooldownTask = Task.CompletedTask;
@@ -15,7 +15,7 @@ public static class ThrottleExt
private static readonly ConcurrentDictionary<Guid, ThrottleState> ThrottlerStates = new();
public static void Throttle(Func<Task> action, Guid actionId, TimeSpan interval)
public static void Throttle(Func<Task> action, Guid actionId, TimeSpan interval, bool scheduleCallAfterCooldown = false)
{
ArgumentNullException.ThrowIfNull(action);
if (actionId == Guid.Empty)
@@ -24,6 +24,7 @@ public static class ThrottleExt
throw new ArgumentOutOfRangeException(nameof(interval), "Interval must be positive.");
var state = ThrottlerStates.GetOrAdd(actionId, new ThrottleState(action));
state.Action = action;
lock (state.StateLock)
{
@@ -34,7 +35,8 @@ public static class ThrottleExt
}
else
{
state.CallScheduledDuringCooldown = true;
if (scheduleCallAfterCooldown)
state.CallScheduledDuringCooldown = true;
}
}
}