8000 feat(useAsyncState): cancel previous promise and use latest promise by snowbitx · Pull Request #4797 · vueuse/vueuse · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(useAsyncState): cancel previous promise and use latest promise #4797

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

snowbitx
Copy link
@snowbitx snowbitx commented Jun 5, 2025

Add a “cancellable” parameter to ensure that only the latest Promise takes effect, canceling the previous ones. The Promise can also be manually canceled by calling cancel().

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. enhancement New feature or request labels Jun 5, 2025
@ilyaliao
Copy link
Member
ilyaliao commented Jun 6, 2025

Thanks for your PR, would you mind adding some unit tests?

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Jun 7, 2025
@snowbitx
Copy link
Author
snowbitx commented Jun 7, 2025

Thanks for your PR, would you mind adding some unit tests?

Thanks for the suggestion! I've added the unit tests and updated the PR. Please let me know if any further changes are needed.

@OrbisK OrbisK changed the title feat(useAsyncState): Only the latest Promise takes effect, and the pr… feat(useAsyncState): cancel previous promise and use latest promise Jun 10, 2025
@snowbitx
Copy link
Author

Based on testing, I found that by default, the result of a slower previous request might override the latest one.
To prevent this, a cancellable option was introduced to ensure only the latest request's result is retained.
A cancel method is also provided to allow manual cancellation of pending promises.

f589f79a190163cdf253c8816c4dd673

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0