I am monitoring a value continuously for detection. I am wondering will it work reliably if it is a recursive function? Or I should create a Genserver and call it continuously so that it can handle failures? Which are the best cases for using Genservers and which are not.
A GenServer is also just a recursively called function, but it's running in its own process and has some additional functionality on top.
You'll want to model long-running processes as GenServer for several reasons:
I recommend reading the chapter "Working with Multiple Processes" from "Programming Elixir" by Dave Thomas to learn more about processes etc.