Replies: 1 comment 5 replies
-
Assuming you are using Unity, you could implement your own public class Debouncer : IAwaitInstruction
{
private float _remainingSeconds;
public Debouncer(float seconds)
=> Reset(_remainingSeconds);
public void Reset(float seconds)
=> _remainingSeconds = seconds;
bool IAwaitInstruction.IsCompleted()
=> (_remainingSeconds -= Time.unscaledDeltaTime) <= 0;
} You can reset it for each keystroke, and pool it if you want to avoid allocations. _debouncer = new Debouncer(0.5f);
await _debouncer; _debouncer.Reset(0.5f); |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there,
Could you please advise on how to implement a debounce method without any allocations?
https://angular.io/guide/http-optimize-server-interaction
I'm using it for an autocomplete feature, so I need only the last event after a specified delay to trigger the listener. I tried using UniTask but wasn't successful, and unfortunately, I haven't received any responses there, and even AI-generated code didn't work correctly.
Cysharp/UniTask#583
Thanks
Beta Was this translation helpful? Give feedback.
All reactions