Skip to content

Commit

Permalink
fix: don't create a new promise every time the throttled function is …
Browse files Browse the repository at this point in the history
…called
  • Loading branch information
jrmclaurin committed May 28, 2023
1 parent ead88d7 commit 70682fe
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ function throttle<Args: Array<any>, Value>(
return result
}

async function wrapper(...args: Args): Promise<Value> {
function wrapper(...args: Args): Promise<Value> {
nextArgs = nextArgs ? getNextArgs(nextArgs, args) : args
if (!nextArgs) throw new Error('unexpected error: nextArgs is null')
if (!nextArgs)
return Promise.reject(new Error('unexpected error: nextArgs is null'))
if (nextInvocation) return nextInvocation
return (nextInvocation = (delay || Promise.resolve()).then(invoke))
}
Expand Down

0 comments on commit 70682fe

Please sign in to comment.