[erlang-questions] gen_server & wait/notify

Chris Waymire chris@REDACTED
Fri Sep 29 02:58:08 CEST 2017


I need some help finding a pattern/solution to a problem that is proving
more difficult then it should, it seems.

I have a gen_server module that needs to take an asynchronous
request/response operation and expose it as a synchronous operation.
Typically I would use receive to block and have the asynchronous operation
issue a message to unblock it but that won't work (i believe) with a
gen_server since it loops over receive and forwards them to calls to
handle_info. The code below demonstrates the core of the matter of what i'm
talking about. I'm not sure what the solution would be to achieve this
functionality while using the gen_server behaviour.



handle_call({request, Data#data{uid=UID}}, _From, State) ->
    make_asycnc_req(Data),
    receive
        {UID, Response} -> {reply, Response, State}
    end.

handle_info({response, Response#response{uid=UID}}, State) ->
    self() ! {UID, Response},
    {noreply, State}.

Thanks,

-- Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170928/af36d8b7/attachment.htm>


More information about the erlang-questions mailing list