3 ms·
Question about elixir: In the article's example, it looks like the HTTP.get function call is turning the asynchronous message into a blocking call. Is that comm
by Myrmornis 10y ago
Question about elixir: In the article's example, it looks like the HTTP.get function call is turning the asynchronous message into a blocking call. Is that common in elixir/erlang, for libraries to provide blocking utilities?
- masklinn 10y ago> Is that common in elixir/erlang, for libraries to provide blocking utilities? It's very common to have blocking API as that's convenient and better hides the implementation details of the API. Note that the blocking is completely local, it'll simply yield back to the scheduler and some other process will get to run (and BEAM is preemptive so after a number of operations — reductions in BEAM parlance — it's going to deschedule the current process and let something else run even without IO calls). And of course you can trivially "unblock" the call by creating a wrapper process for that call.
- Arcsech 10y agoYes, it's quite common for Elixir libraries to provide blocking calls. If your program is well-designed though, the calling process will be "blocked" but other processes will be executing at the same time. So having a process waiting on a HTTP call has no impact on the overall performance of the system. This is one of the big reasons why Erlang/Elixir's model of having many processes is awesome. It's also very easy to use the async/await pattern if you want to make a call, do other work, and get the data from the call at some later point.