Files
annotations/Azaion.Common/Extensions/ThrottleExtensions.cs
T
Alex Bezdieniezhnykh 5a592e9dbf rework to Azaion.Suite
2024-11-21 13:41:32 +02:00

19 lines
475 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();
_ = Task.Run(async () =>
{
await Task.Delay(throttleTime ?? TimeSpan.FromMilliseconds(500));
_throttleOn = false;
});
}
}