Files
annotations/Azaion.Annotator/Extensions/ThrottleExtensions.cs
T
Alex Bezdieniezhnykh 9436e96d81 gallery manager WIP
2024-08-30 18:15:02 +03:00

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