Created
August 22, 2022 14:49
-
-
Save Greenheart/aadd30f919b0fc2346d52ab62f27fa2e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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