gen_server stands for "generic server", a module behaviour in Erlang.
Questions tagged [gen-server]
315 questions
3
votes
0 answers
Why there is no "start_monitor" for gen_server?
Is there any particular reason why there is no start_monitor as an equivalent of spawn_monitor?
Is this simply not needed since gen_servers are usually started by supervisors?
I would like to get a notifications when my temporary workers crash. What…

Jaka
- 1,205
- 12
- 19
3
votes
1 answer
How can I get notification on async failed in GenServer?
In elixir GenServer, there are sync and async methods, handle_cast and handle_call. In the async case, if the method failed, how can I get the notification?
The method failed means in the handle_call method, I need to define some logic to…

Joey Yi Zhao
- 37,514
- 71
- 268
- 523
3
votes
2 answers
What is the gen_server's State life cycle
I am new learner on Erlang, I have questions about Erlang variable's life cycle.
Reference from Erlang gen_server comunication
-module(wy).
-compile(export_all).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,…

Neil
- 2,714
- 11
- 29
- 45
3
votes
1 answer
Do you have to use worker pools in Erlang?
I have a server I am creating (a messaging service) and I am doing some preliminary tests to benchmark it. So far, the fastest way to process the data is to do it directly on the process of the user and to use worker pools. I have tested spawning…

Mike5050
- 625
- 1
- 7
- 22
3
votes
1 answer
Erlang: How to properly dispatch a gen_server with start_child in a supervisor and call the API
I have a gen_server in my cavv application that I need to start first to execute a call to. I want to use a command dispatcher for this. For a short example, this it the gen_server's API:
a gen_server:…

jvdveuten
- 621
- 4
- 23
3
votes
1 answer
What happens when the monitored process dies before handle_call is complete?
I have a question about timing of monitored/linked process dying, and I can't think of how to test it in practice. Here is the scenario I am worried about.
Let's say I have a process called master and slave.
master sets trap_exit to true.
master…

Andriy Drozdyuk
- 58,435
- 50
- 171
- 272
3
votes
1 answer
Debounce events with Elixir
I am getting a stream of events from MQ into my Elixir consumer.
In the consumer I need to:
Aggregate events by their IDs and
Send aggregated data for an ID downstream, if there is no new data for that ID for 3 minutes.
Data set is not big in my…

arkadiy kraportov
- 3,679
- 4
- 33
- 42
3
votes
1 answer
Why does my gen_server implementation give a timeout?
I am trying to learn Erlang and OTP, and so I am currently trying to get a handle on gen_server.
I wrote a quick gen_server implementation of:
-module(test).
-behavior(gen_server).
%% API
-export([start/0, add/1]).
-export([init/1, terminate/2,…

KallDrexx
- 27,229
- 33
- 143
- 254
3
votes
1 answer
Should I not call gen_server:stop() directly?
In the LYSE book the author handles the termination of the server as follows:
%% Synchronous call
close_shop(Pid) -> gen_server:call(Pid, terminate).
handle_call(terminate, _From, Cats) ->
{stop, normal, ok, Cats}.
terminate(normal, Cats) ->
…

Andriy Drozdyuk
- 58,435
- 50
- 171
- 272
3
votes
1 answer
What's wrong with my gen_server implementation?
Following the LYSE book, I tried to re-implement the kitty_server2 with gen_server. But for some reason I am getting this error:
37> Cat1 = kitty_server3:order_cat(Pid, carl, brown, 2).
Ordeirng cat!** exception exit: {{function_clause,
…

Andriy Drozdyuk
- 58,435
- 50
- 171
- 272
3
votes
1 answer
Error in gen_server also terminates the calling process?
My gen_server contains a method like this:
handle_call(error, From, State) ->
io:format("Inside the handle_call error~n"),
1/0.
It provides a start (not start_link) function:
start() ->
gen_server:start({local, ?MODULE}, ?MODULE, [],…

Tiger
- 404
- 1
- 4
- 13
3
votes
1 answer
Erlang code_change and local function call
I am not sure how to call a local function in a module so that after the code change the latest version of the code will be used. See the following example:
1 -module(test).
2
3 -export([start/0, call/1]).
4 -export([loop/0, add/1]).
5
6 start()…

juro
- 631
- 5
- 13
3
votes
2 answers
Are there different priority in otp gen_server's info, call, cast message queue?
When writing codes, I ask myself which type of message should use call, which type of message should use info?
Below this question, there is another long-time doubt whether there is priority difference between info, cast, call message? whether these…

Chen Yu
- 3,955
- 1
- 24
- 51
2
votes
2 answers
What happened if there is "record = State" in handle_call function?
The handle_call function in gen_server is :
Module:handle_call(Request, From, State) -> Result
But I meet one handle_call function like this:
handle_call(info, _From, #yuv{decoder = undefined} = State) ->
{reply, [], State};
handle_call(info,…

why
- 23,923
- 29
- 97
- 142
2
votes
1 answer
Can the GenServer `handle_continue` callback directly be invoked from another process?
The handle_continue callback of a GenServer can be invoked by returning {:noreply, state, {:continue, :foo} from another callback inside the same GenServer.
If I have a small cascade of separate steps after the GenServer.init callback:
defmodule…

jakobfp
- 83
- 7