<div><br></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">tis 22 juni 2021 kl. 18:05 skrev Andreas Schultz <<a href="mailto:andreas.schultz@travelping.com">andreas.schultz@travelping.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<br><br>send_request and friends are unusable in their current form. </div></blockquote><div dir="auto"><br></div><div dir="auto">That is plainly just not true. </div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>What is required would be the ability to the RequestId returned from gen_server:send_request/2 to match the returned message (for example in the header of handle_info/2 method).<br>Something like this:<br><br><font face="monospace"> handle_call(Call, From, #state{other = Other} = State) -><br> ReqId = gen_server:send_request(Other, Call),<br> {noreply, State#state{pending = {ReqId, From}}}.<br><br> handle_info({ReqId, Reply}, #state{pending = {ReqId, From}} = State) -><br> gen_server:reply(From, Reply),<br> {noreply, State}.</font><div><font face="monospace"><br></font></div><div dir="auto"><font face="arial, sans-serif">This is currently not possible, because the internal structure of the reply message is undocumented and even changed between OTP 23 and 24</font></div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div dir="auto"></div></div></div></blockquote><div dir="auto"><br></div><div dir="auto">It would have been a *major* mistake to document it. There are a lot of improvements that would be impossible to implement in a compatibile manner if it was documented. For example those improvements made in OTP 23 and 24. Be prepared for more changes introduced at any time (even in a patch). <br></div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div dir="auto">Currently the only way to do this would be something like this for multiple outstanding requests:<br></div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br></div><div><font face="monospace"> handle_info(Msg, #state{pending1 = {ReqId1, From1}, pending1 = {ReqId2, From2}, pending1 = {ReqId3, From3}} = State) -><br> case check_response(Msg, ReqId1) of<br> {reply, Reply} -><br> gen_server:reply(From1, Reply);<br> no_reply -><br> case check_response(Msg, ReqId2) of<br> {reply, Reply} -><br> gen_server:reply(From2, Reply);<br> no_reply -><br> case check_response(Msg, ReqId3) of<br> {reply, Reply} -><br> gen_server:reply(From3, Reply);<br> no_reply -><br> ok<br> end<br> end<br> end.</font><br></div><div><br>This could be optimized by using a map or list for the pending requests, but it would still require one to iterate over the values and check the message against each request id.</div></div></blockquote><div dir="auto"><br></div><div dir="auto">We have on the todo list to improve handling of multiple outstanding request made via send_request() for OTP 25. </div><div dir="auto"><br></div><div dir="auto">Regards,</div><div dir="auto">Rickard</div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div dir="auto"></div><div><br></div><div>Regards,</div><div>Andreas</div></div></div><div dir="ltr"><div><div><br>-- <br>Andreas Schultz</div></div></div>
</blockquote></div></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">Rickard Green, Erlang/OTP, Ericsson AB</div>