Skip to content
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

feat: add promiseDebounce function #109

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aleclarson
Copy link
Member

@aleclarson aleclarson commented Jul 13, 2024

Tip

The owner of this PR can publish a preview release by commenting /publish in this PR. Afterwards, anyone can try it out by running pnpm add radashi@pr<PR_NUMBER>.

Summary

It's like debounce but each call returns a promise that doesn't resolve unless that call is the last call before the timeout expires. In other words, only when the call finally succeeds, the returned promise will resolve with the function result.

Basically, if you have a debounced function whose result could be useful, you'll want to use promiseDebounce instead.

Naming is not final. Share your thoughts below!

For any code change,

  • Related documentation has been updated, if needed
  • Related tests have been added or updated, if needed
  • Related benchmarks have been added or updated, if needed

Does this PR introduce a breaking change?

No

Bundle impact

Status File Size Difference (%)
A src/curry/promiseDebounce.ts 337 +337

@aleclarson aleclarson added the new feature This PR adds a new function or extends an existing one label Jul 14, 2024
@aleclarson aleclarson added this to the v12.3.0 milestone Sep 21, 2024
if (timeout !== undefined) {
clearTimeout(timeout)
timeout = undefined
const oldResolver = resolver
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const oldResolver = resolver
const oldResolver = resolver
resolver = undefined

@aleclarson aleclarson modified the milestones: v12.3.0, v13.0.0 Nov 20, 2024
@aleclarson
Copy link
Member Author

Delaying this until v13, which is when debounce will have its cancel method reworked to be similar to how promiseDebounce's cancellation works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature This PR adds a new function or extends an existing one
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant