If I’ve got two processes, A
and B
, and I use send_request/4
with both, like this:
ReqIds2 = gen_statem:send_request(A, ReqA, LabelA, ReqIds),
ReqIds3 = gen_server:send_request(B, ReqB, LabelB, ReqIds2),
%...
Then I get sent messages that look like {[alias|#Ref<...>],RespA}
, and there’s no obvious way to figure out which of the following is correct:
MaybeA = gen_statem:check_response(Msg, ReqIds, true),
MaybeB = gen_server:check_response(Msg, ReqIds, true),
A few questions
- Are the
request_id_collection
types compatible betweengen_server
andgen_statem
? The fact that you construct them withgen_server:reqids_new/0
andgen_statem:reqids_new/0
suggests not, even if they are. Perhaps these helpers should have been ingen
? Although I don’t think that’s a public module…? - Should I be using the same
ReqIds
for multiple processes? Is this sensible? - How do I differentiate between
A
andB
responses? Labels (due to the API) feel like they belong togen_server
andgen_statem
, rather than to the caller orA
andB
…
Possible enhancement
The other problem with response messages is that they’re not tagged, which makes them hard to distinguish from normal handle_info
or handle_event(info, ...
, which is kinda annoying.
Is it worth adding gen_statem:send_request/5
which takes a Tag
parameter so that the response message is {Tag, Response}
?