Qqwy
Clever OTP tricks
What things in OTP-land using Processes, GenServers, Supervision Trees and the likes have you come across and found clever enough to tell other people about?
I myself recently learned about Process.send_after/3, and that it is entirely possible for a process to itself call send_after to remind itself about something later. I really like how one can combine it with GenServer.handle_info/2 to basically create a Process that ‘lets itself tick’.
It might have somewhat limited uses, but for my use case (entities governed by finite state machines that might change state depending on passed time) it works really gracefully.
Most Liked
gausby
Notice for state machines using the :gen_fsm behaviour there are some functions dealing with sending delayed events and messages to the process itself, such as start_timer/2 which will send a term to the current state in the form {:timeout, _timer, *term*}; and send_event_after/2 which will send a change event message to the state machine. Both returns a reference that can be used to cancel the timer using cancel_timer/1.
Popular in Discussions
Other popular topics
Chat & Discussions>Discussions
Latest on Elixir Forum
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









