feat: async debounce - #150
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds async-safe debounce/throttle utilities and method decorators so async functions always return Promises (aligning semantics with async memoization), plus a small refactor to centralize the MethodDecorator type.
Changes:
- Add
_asyncDebounce/_asyncThrottleto provide Promise-based coalescing semantics for async functions. - Add
@_AsyncDebounce/@_AsyncThrottledecorators for async methods and extend test coverage for the new APIs. - Move the generic
MethodDecorator<T>helper type todecorator.util.tsand update imports accordingly.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/js-lib/src/decorators/memo.util.ts | Removes the MethodDecorator type from memo utilities (relocated). |
| packages/js-lib/src/decorators/memo.decorator.ts | Switches MethodDecorator import to decorator.util.ts. |
| packages/js-lib/src/decorators/decorator.util.ts | Adds the shared generic MethodDecorator<T> type definition. |
| packages/js-lib/src/decorators/debounce.ts | Refactors debounce timing state and introduces _asyncDebounce / _asyncThrottle. |
| packages/js-lib/src/decorators/debounce.test.ts | Adds tests for _asyncDebounce / _asyncThrottle. |
| packages/js-lib/src/decorators/debounce.decorator.ts | Adds @_AsyncDebounce / @_AsyncThrottle decorators for async methods. |
| packages/js-lib/src/decorators/debounce.decorator.test.ts | Adds tests for the new async decorators. |
| packages/js-lib/src/decorators/asyncMemo.decorator.ts | Switches MethodDecorator import to decorator.util.ts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
frodi-karlsson
force-pushed
the
async-debounce
branch
from
July 15, 2026 14:23
2dab955 to
e50ebcb
Compare
frodi-karlsson
marked this pull request as ready for review
July 15, 2026 14:55
kirillgroshkov
approved these changes
Jul 15, 2026
kirillgroshkov
left a comment
Member
There was a problem hiding this comment.
Ok, I trust you that it works.
|
🎉 This PR is included in @naturalcycles/js-lib-v15.84.0 🎉 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I recommend we have async versions of these to match asyncMemo
I ran into this with
runInBackgroundas follows, in a way that broke at runtime:There's still a small quirk with this implementation:
which is fine for the function variant, but for decorated variants it means
actually can return
Promise<number | undefined>which is still better than returning a syncundefined