Skip to content

Instantly share code, notes, and snippets.

@romasan romasan/peakBounce.js
Last active Nov 15, 2019

Embed
What would you like to do?
const peakBounce = (interval, count) => {
let iCount = 0;
let stack = [];
setInterval(() => {
const part = stack.splice(0, count);
part.forEach(fn => fn())
iCount = part.length;
}, interval);
return (fn, ...a) => {
if (typeof fn !== 'function') {return}
if (iCount < count) {
iCount++;
fn(...a);
} else {
stack.push(() => {
fn(...a);
})
}
}
}
const pb = peakBounce(1000, 2);
const f = i => {console.log(i)}
pb(f, 1);
pb(f, 2);
pb(f, 3);
pb(f, 4);
pb(f, 5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.