throttle-queue


When called, a throttle queued function will put itself in a queue. Each call in the queue will be executed after the configured delay. By default, the first call of the queue will be executed after a timeout of 0ms. This default can be disabled. The queued calls can be cancelled by calling the cancel function. Check out the Quickstart in the repository.

Demo - Throttle Queued Click Handler

counter: 0

// DOM element refs
const counterValue = document.getElementById('counter-value');
const increaseCountButton = document.getElementById('increase-count');
const cancelButton = document.getElementById('cancel-count');

let count = 0;

// non throttle queued click handler
function onClickHandler() {
    count++;
    counterValue.innerHTML = count;
}

// throttle queued click handler
const tqClickHandler = throttleQueue(onClickHandler, 1000);

// assign click handlers
increaseCountButton.onclick = tqClickHandler;
cancelButton.onclick = tqClickHandler.cancel;