gen_server and priority queues

Ulf Wiger <>
Mon Oct 24 18:16:29 CEST 2005


You can't to it with gen_server - at least not in any
acceptable way. Just today, I was toying with the idea
of hacking gen_server to support this. :)

You don't need a bridge. Just make sure to start your
process with proc_lib:start_link/3, and acknowledging
with proc_lib:init_ack/2. Then you need to handle
system messages as well.

You could also use plain_fsm. See jungerl.

/Uffe


Den 2005-10-24 17:38:11 skrev Richard Cameron <>:

>
> I want to implement a server which processes messages in order of  
> priority. I know I can do this in pure Erlang as:
>
> handle(high, State) ->
>      receive {high,Msg} ->
>              do(Msg,State)
>      after 0 ->
>              handle(medium, State)
>      end;
> handle(medium, State) ->
>      receive {medium,Msg} ->
>              do(Msg, State)
>      after 0 ->
>              handle(low, State)
>      end;
> handle(low, State) ->
>      receive {_,Msg} ->
>              do(Msg, State)
>      end.
>
> ... but what I really want is to be able to do this within OTP's  
> gen_server behaviour. Is there a nice way to do this, or do I just need  
> to roll my own server and then attach it to my supervision tree with a  
> bridge?
>
> Richard.



-- 
Ulf Wiger



More information about the erlang-questions mailing list