Event on page closed for stop a watchdog #3378
fjosegalan
announced in
Q&A
Replies: 3 comments 1 reply
-
Sorry for my code quoting.... I did not managed it properly |
Beta Was this translation helpful? Give feedback.
1 reply
-
We don't have a specific event that is triggered on page close. However, a recent PR (#3388) added a way to keep track of whether the client websocket is still connected, so you can use that for now to detect if your background task should stop or keep running. |
Beta Was this translation helpful? Give feedback.
0 replies
-
related: #2671 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello
I am playing around with reflex and the test I am doing is as follow:
Before start the reflex APP I call a socket from back end to provide some data to states.
Then in the main page load event "on_load" I call an app state method to enable a watchdog with the socket, to conditionally render some message in the page about socket not connected.
App start:
The App state looks like this:
As you can see there is a background task checking for the connection, and if not connected tries to reconnect it every 1 second.
What is the problem?
I set some logs (basic print functions) and the background task starts when the page is loaded, it works as expected. But when the page is closed on browser I have noted that the background task still running forever, as stated even with the web browser closed.
First question:
Is my approach to watchdog the socket connection ok?
Then second question:
Is there an event about "closed page"? or "on closing" page? to stop the background event for the watchdodg.
Regards
Fran Galan
Beta Was this translation helpful? Give feedback.
All reactions