Erlang / Erlang Basics Interview questions
Explain the execution flow of a gen_server call?
gen_server:call/2 looks like a normal function call, but underneath it's a request/reply
protocol built out of plain message passing plus a monitor for safety.
sequenceDiagram
participant Caller
participant GenServer as gen_server process
Caller->>GenServer: {'$gen_call', {Caller,Ref}, Request}
Note over GenServer: handle_call/3 runs
GenServer-->>Caller: {Ref, Reply}
Note over Caller: call/2 unwraps Reply and returns it
Step by step: the caller sends a tagged message containing its own PID and a fresh unique reference, then
sets up a monitor on the server and blocks in a receive waiting for a reply tagged with that same
reference (with a default 5-second timeout). The server's handle_call/3 callback runs, returning
{reply, Reply, NewState}, and the framework sends Reply back tagged with the original
reference. The monitor exists so that if the server dies mid-call, the caller gets a 'DOWN' message
instead of hanging forever.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
