Gen_server call: thrown from Mod: handle_cast

This is the code I have:

handle_cast(start, #state{started = false} = State) -> gen_server:cast(self(), add_process), {noreply, State#state{started = true}}; handle_cast(add_process, State) -> ... 

Is it possible to call gen_server:cast from insinde in the handle_cast function? I expect this to cause handle_cast return a new state, and then the add_process message will be processed immediately.

+4
source share
1 answer

This is correct, except that the message cannot be processed "immediately" - it is placed in the message queue, and the messages before it in the queue will be processed first.

As you probably already figured out, this applies to gen_server:cast and messages sent using ! , but not to gen_server:call , which can lead to a deadlock.

+7
source

All Articles