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

Koener Antoine <>
Thu Mar 3 14:00:06 CET 2011


On Mar 3, 2011, at 10:57 , Attila Rajmund Nohl wrote:

> 2011/3/2, Nav <>:
>> Hi,
>>
>> Is there a way to stop handle_cast(..) being called (i.e. stop
>> gen_server from reading data from queue) for a while?
>>
>> I am trying to implement a logic, while processing, gen_server should
>> not accept any messages and let messages stay in its queue. (Other
>> processes can still send messages using gen_server:cast())
>
> Why not do this processing in a handle_info? Trigger the calling of
> the handle_info call by sending a message to the gen_server.
>

Was thinking about something like this:

skip() ->
	skip(?MODULE).

skip(Node) ->
	gen_server:cast(Node, skip);

unskip() ->
	skip(?MODULE).

unskip(Node) ->
	gen_server:cast(Node, unskip);


[...]

handle_cast(_Any, #state{skip=true} = State) ->
	{noreply, State};

handle_cast(skip, State) ->
	{noreply, State#state{skip=true}};

handle_cast(unskip, State) ->
	{noreply, State#state{skip=false}};



> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:
>



More information about the erlang-questions mailing list