First of all. I have to say sorry that my question is not about code and might be vague.
But as I am studying GenServer and OTP section, one questions came up in my mind.
How can I use GenServer in my project?
In my application, I mostly use external api, such as Stripe and Twilio.
So I tried to use GenServer like this…
Client
def send_sms(phone_numbers, body, from_number, account, token) do
GenServer.cast(__MODULE__, {:send_sms, phone_numbers, body, from_number, account, token})
end
Server
def handle_cast({:send_sms, phone_numbers, body, from_number, account, token}, state) do
Sms.send_sms(phone_numbers, body, from_number, account, token)
{:noreply, state}
end
But I don’t understand what the benefit is when I use GenServer here.
I want to get a response, so I have to use GenServer.call instead of cast.
what if I want to send 10000 sms using GenServer.call? GenServer,call is synchronous call and wait for response, is it correct using GenServer.call for this case?
I don’t think I fully understand a concept, benefit of using GenServer, and haveing trouble understanding it and adopting it for my use case.
Please help!