GenServer handle_call

This is more of a clarification.

When I create a handle_call callback for a GenServer i.e.

def handle_call(:pop, _from, [h|t]) do
    {:reply, h, t}

The term [h|t] will be pattern matched against anything the GenServer is maintaining right?

Also: How do you post source code in this forum?

1 Like

Correct. The third argument to handle_call is the gen server state. In the case of your example that state is purely a list, but it can be any Elixir term.

Formatted code can be displayed by wrapping the text block in ```

1 Like

This forum uses markdown for posts with some extensions.

Also you can obviously use the toolbar right above the textbox.

1 Like