namespace Azaion.Common.Extensions; public static class ThrottleExt { private static readonly Dictionary LastExecution = new(); private static readonly object Lock = new(); public static async Task Throttle(this Func func, TimeSpan interval, CancellationToken ct = default) { ArgumentNullException.ThrowIfNull(func); lock (Lock) { if (LastExecution.ContainsKey(func) && DateTime.UtcNow - LastExecution[func] < interval) return; func(); LastExecution[func] = DateTime.UtcNow; } } }