mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 22:26:31 +00:00
fix throttle ext
fix configs fix build scripts
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user