How can I keep calling a server function everytime it returns? (http long polling) #2073
Unanswered
maartensson
asked this question in
Q&A
Replies: 1 comment 4 replies
-
Here's an example I just threw together of an effect that triggers a resource to refetch every time it resolves. If there were something like a forward ref that could be used to pass the resource into its own source signal that would be even more elegant but... this is probably fine? let resource = create_resource(
|| (),
|_| async {
logging::log!("fetching resource");
gloo_timers::future::TimeoutFuture::new(500).await;
logging::log!("loaded resource");
},
);
create_effect(move |prev| {
resource.track();
if prev.is_some() {
resource.refetch();
}
}); |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I want to do http long polling to listen for changes on the server.
And I am wondering how I can make the component keep fetching the resource from the server everytime the server returns either an update or a timeout.
Here is an illustration of the flow.
server == serverfunction
Beta Was this translation helpful? Give feedback.
All reactions