[erlang-questions] Disallowing gen_server:handle_cast() for a while?

Matthew Sackman <>
Wed Mar 2 15:34:42 CET 2011


On Wed, Mar 02, 2011 at 04:27:41PM +0200, Nav wrote:
> Does gen_sever ensure that while I am executing
> 
> handle_cast(message1,...) ->  {no spawn ..etc}
> 
> the next message stays in the mailbox?

Yes. Each process is a single process/thread. It cannot do multiple
things at the same time.

> timer:sleep is not an option since my logic would be inside gen_server itself.

It's rare to have good reason to alter gen_server's code yourself,
though that might not be what you're suggesting.

> My main requirement
> 
> handle_cast(message1,...) ->
> 
>    %% force gen_server to not read any message from queue
> 
>    %% some actions
> 
> end.
> %% now gen_server can read message as before.

That's exactly what it does.

Matthew


More information about the erlang-questions mailing list