add offset

fixes
add visual validation border and validate functionality
This commit is contained in:
Alex Bezdieniezhnykh
2024-12-28 15:51:27 +02:00
parent 5fe46cd6f5
commit 8b94837f18
27 changed files with 251 additions and 128 deletions
+21 -5
View File
@@ -2,18 +2,34 @@
public static class ThrottleExt
{
private static bool _throttleOn;
public static async Task Throttle(this Func<Task> func, TimeSpan? throttleTime = null, CancellationToken cancellationToken = default)
private static bool _throttleRunFirstOn;
public static async Task ThrottleRunFirst(this Func<Task> func, TimeSpan? throttleTime = null, CancellationToken cancellationToken = default)
{
if (_throttleOn)
if (_throttleRunFirstOn)
return;
_throttleOn = true;
_throttleRunFirstOn = true;
await func();
_ = Task.Run(async () =>
{
await Task.Delay(throttleTime ?? TimeSpan.FromMilliseconds(500), cancellationToken);
_throttleOn = false;
_throttleRunFirstOn = false;
}, cancellationToken);
}
private static bool _throttleRunAfter;
public static async Task ThrottleRunAfter(this Func<Task> func, TimeSpan? throttleTime = null, CancellationToken cancellationToken = default)
{
if (_throttleRunAfter)
return;
_throttleRunAfter = true;
_ = Task.Run(async () =>
{
await Task.Delay(throttleTime ?? TimeSpan.FromMilliseconds(500), cancellationToken);
await func();
_throttleRunAfter = false;
}, cancellationToken);
}
}