Open kimlai opened 7 years ago
Hi @kimlai - so sorry for the late reply. Yes, what you're suggesting makes total sense. It will likely be a while before I can look into this. In the meantime, feel free to put in a PR.
Thanks for your input on the above issue - much appreciated 👍
Hi!
If I understand the code correctly, it seems that you're using a
GenServer
to be able to store theauth_token
andclient_id
across requests.Since
GenServer
calls are blocking, this means that it is not possible to send concurrent requests to MangoPay's API, eachcall
having to wait for the previous one to have been processed before being executed. This behaviour can easily be observed from aniex
session:This will output responses sequentially, and start sending
GenServer
timeout errors after a while.It seems to me that instead of passing all calls through a
GenServer
, you could only use one for authentication. It could look something like this:This will make it possible to send concurrent requests to MangoPay, while using the blocking nature of
GenServer.call
to block all requests while an authentication request is pending. There might be other concerns to deal with in the authenticationGenServer
(like callingsend_after
to re-authenticate when the current token expires), but I think that the key point is to keep theGenServer
around authentication (ie around the actual state of the application) instead of the whole client.It will also simplify the code of
Mangoex.Client
quite a bit.What do you think?