I am aware the process wouldn’t terminate by itself. That is why I have this handle_info function that receives the :timeout and returns { :stop, :normal, state}.
I use GenServer to achieve a sequential access of all change requests over a single instance of a certain data structure (“class”) that otherwise gets persisted (by this very same module) in the database. A “manager” process gets instantiated for each such data structure instance and more than one user (and more than one UC) can thus modify the state that it controls. All state-modifying logic is thus centralized in a single module and all access to it is sequential.
The process is made temporary because I don’t want it restarted in case of a real error (such as writing into the db). It times out because it is set to keep this state for “some” time in the server-side memory so that it doesn’t take constantly loading and converting 10’s or 100’s K of from JSONB to embedded schema, but only if User inactive for some time.
And yes, I would like to have the client code call the pid fetching once more if the process is terminated (in-between the two lines of code), but I needed to know if somebody knew something I don’t (for instance, I searched for on how to retrieve the info on time remaining until the timeout for a process, but found nothing). I mean this problem is so obvious and should be a frequent issue for anyone who uses temporary GenServer with timeouts. Maybe there is already some design pattern to handle this.


















