I have a use case where I have multiple functions firing simultaneously. Each function can be called multiple times but I need to pick out only one return value. Im using debounce and it does work as intended. Even if I have 10 return values, I get only 1 return at the end. However if there are unique values, I want all the unique values returned
What is happening
-----1----2-----2---2----2----2----3-----3---3---3---3---3------>
(Only 1 value is returned)
-------------------3--------------------------------------------->
What I want
-----1----2-----2----2----2----2----3-----3---3---3---3---3------>
(Return all unique values)
-------------------1-------------------2--------------------3---->
What I have tried (Example)
var _ = require('lodash');
function printOne () {
handleDebounce(1);
}
function printTwo () {
handleDebounce(2);
}
function printThree () {
handleDebounce(3);
}
const handleDebounce = _.debounce((msg) => {
console.log(msg)
}, 2000, );
printOne();
printTwo();
printTwo();
printTwo();
printThree();
printThree();
printThree();
Output -> 3
Expected Output -> 1 2 3
Should I use a set to have a form of local cache and then get unique values? Any pointers would be welcome