#I'm pretty sure there's also a solution with recursion and only one variable
Explore tagged Tumblr posts
transienturl · 1 year ago
Text
const delayPromises = []; export const throttledApiFetch = (...args) => new Promise((resolve) => { const currentPromises = [...delayPromises]; delayPromises.push( // eslint-disable-next-line promise/param-names new Promise((resolveDelay) => Promise.all(currentPromises).then(() => { resolve(apiFetch(...args)); setTimeout(resolveDelay, 1000); }) ) ); });
now this is cursed. effectively unbounded memory usage, nested promise constructors.
4 notes · View notes