mirror of
https://github.com/azaion/annotations.git
synced 2026-04-23 01:56:31 +00:00
add debounced config save after 7 sec after window resizing/moving
This commit is contained in:
@@ -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);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user