Aadil Levy
Aadil Levy

Reputation: 23

Does OTP gen_server intercept received messages

I am using OTP's gen_server. Can I use a function which sends a message to some process and receives the response? My worry is that this response message would be intercepted by get_server and therefore processed by handle_info instead of by my function.

If I want to have such function, how do I do it?

Upvotes: 0

Views: 108

Answers (1)

legoscia
legoscia

Reputation: 41528

If you have a receive expression within one of the gen_server callback functions, it will not be interrupted. It would however receive messages meant for the gen_server itself, so you may want to use a very specific pattern in order to leave other messages in the process mailbox for later processing.

Note that this would make the gen_server process unresponsive to other calls while waiting for the response message.

Upvotes: 6

Related Questions