I'm trying to debounce the user input into two boxes and then call an expensive function. Here is a minimum example, that doesn't work:
$('#slider_min').on('keyup', LetItRoll )
$('#slider_max').on('keyup', LetItRoll )
async function LetItRoll(){
const amin = debounceProimse(UpdateSliderMin,300)
const amax = debouncePromise(UpdateSliderMax,300)
const result = await Promise.all([amin,amax])
const result_value = [amin,amax]
alert(result)
return result
}
function UpdateSliderMin(){
const slider_min = document.getElementById('slider_min').value
return slider_min // not a promise, but doesnt work if I create a promise
}
function UpdateSliderMax(){
const slider_max = document.getElementById('slider_max').value
return slider_max
}
For debouncePromise I have tried the suggestions both in Debounce function implemented with promises https://www.30secondsofcode.org/js/s/debounce-promise
Actually, I dont really care if the debounce returns a promise because I think "on" never returns anything, so cannot create a chain? Either way, I have restructured the same with other debounce code on the internet, including lodash debounce. They all give the same thing: if you type fast enough then you create multiple calls to "alert"
I also read in https://jakearchibald.com/2015/tasks-microtasks-queues-and-schedules/ that callbacks may have higher priority over microtasks, so conceivably that is what is happening?
I was also wondering if each click was creating a separate version of debounce, so I tried taking the chain of Promises to be a global variable so each new debounce would add to the old promise. That didnt work either.
Seems this should be easy, but I am completely stumped....