How do you timeout a server action?
With axios and fetch, you can specify a timeout but how do you do this with server actions?
20 Replies
Bad Questions
An article by Josh
I get this but it's a very general question. I'll reframe and add more context
specifically I'm looking for what are you trying to accomplish? what code have you tried? etc
a lot of times the right solution isn't the answer to your question it's a solution to your problem
So I know with fetch you can add a timout for api request to fetch data so if the data is not fetched during that time, it will throw an error and you can handle that and show to the user that request took too long
Now how do you achieve the same with server actions? It's not an api path, so can't use fetch (I think)
adding code ...
how do you timeout if the quest is not done in like 10 seconds?
const handleButtonClick = async () =>{
const response = await generateBulletList(userMessage || "");
}
<Button
onClick={handleButtonClick} > button </Button>
format that plz
Yea was trying to do that, sry I don't know the key or shortcut 🥲
is this better?
yur
I was trying to use AbortController, but had no idea how to use with server action since it's like a function.
10 seconds from the client or 10s execution time
10s from client is just not a good idea in general
yea
from client
why
that's a terrible idea
y?
you're fucking any user trying to use your app with a bad internet connection
ahhh haha true
sry never done this stuff 😅 this is kinda my first prod level project
a better option is to not cancel, but show some sort of 'hey, this is taking longer than normal, we are trying' or whatever
so you don't have to interact with the request at all, just use a regular setTimeout
yup I wanted to do both, so a message in like 10sec and then cancel if it takes 20 sec
you should never cancel
again your fucking users on slow Internet speeds
and there is no point in canceling
so a set timeout on client side and nothing on server side?
and set timeout just shows the message, never cancel the req...
Solution
yessir
Thnx a lot for the help, will give it a shot