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

how to add support of abortController in react ketting #99

Open
sazyadav opened this issue Sep 1, 2022 · 5 comments
Open

how to add support of abortController in react ketting #99

sazyadav opened this issue Sep 1, 2022 · 5 comments

Comments

@sazyadav
Copy link

sazyadav commented Sep 1, 2022

I wanna add abortController support in react ketting.. Is there any way to use abortController in ketting get request?
@evert Please help on this

@evert
Copy link
Contributor

evert commented Sep 1, 2022

A good place to start with be to add it to the GetOptions type, and from there see where else you would need to add it to drill all the way down to fetch(). I'm definitely open to this!

The trickiest thing to keep in mind is that multiple calls to get() de-duplicate, so if there's 2 separate calls to get(), and the first one aborts, it probably shouldn't cancel because the second one is still waiting. If you can solve that you're well on your way.

@sazyadav
Copy link
Author

sazyadav commented Sep 5, 2022

Thanks For your reply @evert .
In the current implementation how Can I pass abortController signal instance in react-ketting fetch/get request.
the way in below code snippet, passing the signal
useEffect(() => {
const abortController = new AbortController();

setIsLoading(true);
fetch(https://jsonplaceholder.typicode.com/posts/${postId}, {
signal: abortController.signal,
})
.then((response) => {
if (response.ok) {
return response.json();
}
return Promise.reject();
})
.then((fetchedPost: Post) => {
setPost(fetchedPost);
})
.finally(() => {
setIsLoading(false);
});

return () => {
abortController.abort();
};
}, [postId]);

@michaeljenzen
Copy link

The primary blocker I see for getting this to work is the private optionsToRequestInit function in resource.ts would not forward the AbortController signal onwards to the fetcher.

@evert
Copy link
Contributor

evert commented Sep 6, 2022

So the main issue is, how are you going to deal with de-duplicated requests?

For example, it's possible to do 2 GET requests, but Ketting will ensure only 1 goes out. What happens if the first one AbortController and it got aborted. What happens if the second one got an AbortController and it got cancelled?

@AresEkb
Copy link

AresEkb commented Aug 31, 2023

Maybe both GET requests can be invoked with the same signal? So cancelling any of them will cancel the other as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants