Posts

Showing posts with the label gen-server

Genserver state change during handle_info or handle_call

Genserver state change during handle_info or handle_call Suppose I have a simple genserver that mantains a simple :queue as it's state. Items are continually being added with handle_cast. Every 5 seconds I process the queue with Process.send_after. That call gets handled with a call back to handle_info with the current state. The queue gets processed and emptied then a new empty queue is applied as the current state of the genserver. My question is this: What happens when calls come into genserver while the queue is being processed? Since I return a new empty queue to handle_info {:noreply, :queue.new} will that write over items that were being added while I was processing the queue? Or will the genserver casts be themselfs queued up then allowed to finish once handle_info is done? Basically I am concerned about missing items during handle_info. Code: defmodule TcpClient.Queue do use GenServer require Logger def start_link do queue = :queue.new() GenServer.star...