What is the timeout of 'use server' functions?

Context: I plan to use long polling in an app I couldn't find any documentation on how to control timeouts for server functions. How should this be handled?
6 Replies
Madaxen86
Madaxen865mo ago
Not sure if I understand correctly: You want to poll data from a server function with an interval of x seconds. Is that correct? Then you would do something like this.
const getData = cache(async () => {
"use server"
...

},"getData")

const Layout: ParentComponent = (props) => {
//if you need data in your layout
const data = createAsync(() => getData());


onMount(() => {
function revalidateData(){
revalidate(getData.key);
}
//revalidate when returning to tab
document.addEventListener("visibilitychange", refreshWhenVisible);

//poll every 30 seconds
const interval = setInterval(refreshWhenVisible, 1000 * 30);

onCleanup(() => {
document.removeEventListener("visibilitychange", refreshWhenVisible);
clearInterval(interval);
});
});

return <Suspense>
...
<Suspense>
const getData = cache(async () => {
"use server"
...

},"getData")

const Layout: ParentComponent = (props) => {
//if you need data in your layout
const data = createAsync(() => getData());


onMount(() => {
function revalidateData(){
revalidate(getData.key);
}
//revalidate when returning to tab
document.addEventListener("visibilitychange", refreshWhenVisible);

//poll every 30 seconds
const interval = setInterval(refreshWhenVisible, 1000 * 30);

onCleanup(() => {
document.removeEventListener("visibilitychange", refreshWhenVisible);
clearInterval(interval);
});
});

return <Suspense>
...
<Suspense>
Mango Juicy
Mango JuicyOP5mo ago
Not quite what I was asking. I intend to keep a connection open extended time like 30 - 60 seconds for a long running POST request - in this case a use server function Short polls are strait forward. But what happens if the server function is hanging for longer polls? Or is this generally bad practice?
Mango Juicy
Mango JuicyOP5mo ago
Hope this illustration helps:
No description
Mango Juicy
Mango JuicyOP5mo ago
Think of it as a scrappy way of avoiding the complexity of websocket While avoiding the increased load on database of short polling Ideally, I should probably use server sent events, but is that possible in Solid Start?
Madaxen86
Madaxen865mo ago
Then maybe streaming the response back may be an option? Or as you said, use a web socket.
Brendonovich
Brendonovich5mo ago
Server functions don’t have a built in timeout afaik
Want results from more Discord servers?
Add your server