It doesn't work because you are not fully understanding how node-red works. Each time a msg hits that function, all code in the function is executed (including let t
). So when you try to clearTimeout(t);
, t
is empty!
If you want this to work, you will need to store and restore the timer handle t
. See "working with context" in the node-red documentation to understand how you can persist a value between calls.
However, why not use a delay node instead...