-
Notifications
You must be signed in to change notification settings - Fork 65
fix: prevent double reflection log #1210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
return (async (...args: any[]) => { | ||
if (executing) { | ||
// if there's already an execution, make it pending | ||
pendingExecution = args | ||
return null as any | ||
return { type: 'executing' } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be simpler to return a deferred promise here? Then the caller doesn't need to know about the inner workings between result/executing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's a deferred promise in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return a promise here, resolve it somewhere else later. (e.g. not within the promise func body)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That won't work because promises are eager and we don't want that promise to run at all, until the one that is already running is finished. Otherwise we're not debouncing anything. We're just running the functions one after the other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, that wouldn't help, because you need to dedupe higher up in the call stack.
if (pendingExecution) { | ||
await fn(...args).catch((e) => console.error(e)) | ||
res = await fn(...args).catch((e) => console.error(e)) | ||
pendingExecution = null | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do prefer it, hence why we run it right after the current promise is finished
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Closes #1212