bodhilogic
Dead-man Timer
I’ve been playing with GenServer timers and what I would like to do is run a GenServer timer that, when it processes the handle_info() call, causes the web application to redirect to another page. A bonus would be for the redirect to happen only if the user has not interacted with the page since the timer started (i.e. clicking on a button or editing a field resets the timer back to time zero).
My problem is that the redirection requires the conn ‘object’ as one of the parameters but the GenServer, as far as I can see, has no way to obtain the conn ‘object’.
Is there a way to get hold of the conn ‘object’ from within the GenServer ‘processing’?
Or am I doing it completely wrong?
Thanks for taking the time to answer!
Most Liked
peerreynders
If the user doesn’t interact with the page then there is no HTTP request.
- No HTTP request - no redirect.
So unless you are using LiveView there isn’t anything you can do. The timer would have to be based on the client-side (i.e. the browser) and make a request when there is no activity.
With LiveView you would simply change what is currently rendered on the page after the timeout expires - but there is no redirect involved.
EDIT: I forgot about channels - i.e. you might be able to use them to have the server send a message (at timeout) to the browser and have some browser-based code take some action.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









