Files
annotations/Azaion.Annotator/Extensions/ThrottleExtensions.cs
T
Oleksandr Bezdieniezhnykh 78776d37bd rework throttle
reuse throttle mechanism for catching global keys
2024-08-14 02:02:26 +03:00

16 lines
412 B
C#

namespace Azaion.Annotator.Extensions;
public static class ThrottleExt
{
private static bool _throttleOn;
public static async Task Throttle(Func<Task> func, TimeSpan? throttleTime = null)
{
if (_throttleOn)
return;
_throttleOn = true;
await func();
await Task.Delay(throttleTime ?? TimeSpan.FromMilliseconds(500));
_throttleOn = false;
}
}