add debounced config save after 7 sec after window resizing/moving

This commit is contained in:
Oleksandr Bezdieniezhnykh
2024-07-20 19:35:42 +03:00
parent 8869a92730
commit f452059407
2 changed files with 24 additions and 0 deletions
@@ -0,0 +1,16 @@
namespace Azaion.Annotator.Extensions;
public static class FuncExtensions
{
private static CancellationTokenSource? _lastCToken;
public static Action Debounce(this Action func, TimeSpan? throttleTime = null) =>
() =>
{
_lastCToken?.Cancel();
var tokenSrc = _lastCToken = new CancellationTokenSource();
Task.Delay(throttleTime ?? TimeSpan.FromMilliseconds(500), tokenSrc.Token)
.ContinueWith(_ => func(), tokenSrc.Token);
};
}