Skip to content

Instantly share code, notes, and snippets.

@Greenheart
Created August 22, 2022 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Greenheart/aadd30f919b0fc2346d52ab62f27fa2e to your computer and use it in GitHub Desktop.
Save Greenheart/aadd30f919b0fc2346d52ab62f27fa2e to your computer and use it in GitHub Desktop.
const queue = [];
const execute = () => {
const action = queue[0];
if (action) {
action().finally(() => {
queue.shift();
execute();
});
}
};
const debounceQueue = action => {
if (typeof action !== 'function') return;
queue.push(action);
if (queue.length === 1) {
execute();
}
};
export default debounceQueue;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment