{"id":325678,"date":"2021-06-29T15:00:45","date_gmt":"2021-06-29T15:00:45","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=325678"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=325678","title":{"rendered":"\u0421\u0442\u0440\u0435\u043b\u044f\u0435\u043c \u0441\u0435\u0431\u0435 \u0432 \u043d\u043e\u0433\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e GenServer&#8217;\u0430, \u0438\u043b\u0438 \u043a\u0430\u043a \u043c\u044b \u0444\u0438\u043a\u0441\u0438\u043b\u0438 \u043d\u0435\u0443\u043b\u043e\u0432\u0438\u043c\u044b\u0439 \u0431\u0430\u0433 \u0432 Elixir \u043f\u0440\u043e\u0435\u043a\u0442\u0435"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/544\/d4c\/c8e\/544d4cc8e9845c4af85a39b84878cb2a.jpg\" width=\"600\" height=\"400\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0418\u0432\u0430\u043d, \u044f \u2014&nbsp;\u0442\u0435\u0445\u043b\u0438\u0434 \u0432 \u041a\u0430\u0440\u0443\u043d\u0435.<\/p>\n<p>\u0412 \u043a\u043e\u043c\u0430\u043d\u0434\u0435 \u043c\u044b \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Elixir \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u043d\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432.<\/p>\n<p>\u041c\u044b \u0443\u0434\u0435\u043b\u044f\u0435\u043c \u043e\u0441\u043e\u0431\u043e\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0437\u0430 \u043a\u043e\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u043b\u043b\u0431\u0435\u043a\u0430\u0445 GenServer&#8217;\u0430, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043a\u043e\u0434 \u0442\u0440\u0435\u0442\u044c\u0435\u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043f\u043e\u0447\u0435\u043c\u0443 \u044d\u0442\u043e \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0436\u043d\u043e, \u0438 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e, \u043a\u0430\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0445 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u043d\u0430\u043c Elixir \u0438 Erlang, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043b\u043e\u043c\u0430\u0442\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 GenServer&#8217;a \u0438 \u043f\u043e\u0440\u043e\u0434\u0438\u0442\u044c \u0442\u0440\u0443\u0434\u043d\u043e\u0443\u043b\u043e\u0432\u0438\u043c\u044b\u0435 \u0431\u0430\u0433\u0438. \u0415\u0449\u0451 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u043c\u044b \u0431\u043e\u0440\u043e\u043b\u0438\u0441\u044c \u0441 \u0442\u0430\u043a\u0438\u043c \u0431\u0430\u0433\u043e\u043c \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0436\u0438\u0437\u043d\u0438.<\/p>\n<p>\u041f\u043e\u0435\u0445\u0430\u043b\u0438!<\/p>\n<h3>Key-value \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435<\/h3>\n<p>\u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430. \u0410\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044f GenServer&#8217;\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0439 \u0432 Erlang\/OTP \u0438 Elixir. \u041f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0430\u0431\u043e\u0442\u044b GenServer&#8217;\u0430 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442.<\/p>\n<p>\u042d\u0442\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0445\u0440\u0430\u043d\u0438\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u0438\u0437\u043c\u0435\u043d\u044f\u044f \u044d\u0442\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043f\u043e\u0441\u044b\u043b\u0430\u044f \u043e\u0442\u0432\u0435\u0442\u043d\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f.<\/p>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u0442\u043e\u043d\u043a\u043e\u0441\u0442\u044f\u043c \u0440\u0430\u0431\u043e\u0442\u044b GenServer&#8217;\u0430, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043e\u0434\u0438\u043d \u0438\u0437 \u043d\u0438\u0445.<\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u043e\u0435 key-value \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438 \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u043a\u043b\u044e\u0447\u0443.<\/p>\n<p>\u041d\u0438\u0447\u0435\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e: \u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 GenServer&#8217;\u0430 \u0432\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435 \u0441\u0442\u0430\u0442\u0435\u0439 \u0438 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u043e\u0432.<\/p>\n<pre><code class=\"erlang\">defmodule SimpleKeyValue do   use GenServer    def start do     GenServer.start(__MODULE__, %{})   end    def put(pid, key, value) do     GenServer.cast(pid, {:put, key, value})   end    def get(pid, key) do     GenServer.call(pid, {:get, key})   end    # Callbacks   @impl true   def init(state) do     {:ok, state}   end    @impl true   def handle_cast({:put, key, value}, state) do     {:noreply, Map.put(state, key, value)}   end    @impl true   def handle_call({:get, key}, _from, state) do     {:reply, Map.fetch!(state, key), state}   end end<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438. \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043a\u0430\u043a \u0437\u0430\u0434\u0443\u043c\u0430\u043d\u043e. \u041c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438 \u0441\u043c\u043e\u0433\u043b\u0438 \u0432\u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0435\u0433\u043e \u043f\u043e \u043a\u043b\u044e\u0447\u0443<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/692\/c1c\/0ad\/692c1c0ade997bb3c73719f47f835057.png\" width=\"2180\" height=\"624\"><figcaption><\/figcaption><\/figure>\n<h3>\u041b\u043e\u043c\u0430\u0435\u043c GenServer<\/h3>\n<p>\u041f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u0443\u0437\u043d\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0435\u0442\u0430\u043b\u0438 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0439 \u043a\u0443\u0445\u043d\u0438 GenServer&#8217;a.<\/p>\n<p>\u042f \u0441\u0447\u0438\u0442\u0430\u044e, \u0447\u0442\u043e \u043e\u0434\u0438\u043d \u0438\u0437 \u043b\u0443\u0447\u0448\u0438\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u0447\u0442\u043e-\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u2014 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u0447\u0442\u043e-\u0442\u043e \u0441\u043b\u043e\u043c\u0430\u0442\u044c.<\/p>\n<p>\u0410 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u0441\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0441 \u043d\u0430\u0448\u0438\u043c GenServer&#8217;\u043e\u043c, \u0435\u0441\u043b\u0438 \u0432 \u043a\u043e\u043b\u043b\u0431\u044d\u043a\u0435 \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 receive loop:<\/p>\n<pre><code class=\"erlang\">def run_receive_loop(server) do   GenServer.cast(server, :run_receive_loop) end  @impl true def handle_cast(:run_receive_loop, state) do   receive do     msg -&gt; IO.inspect(msg, label: \"RECEIVE LOOP\")   end    {:noreply, state} end<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0451\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u0430\u043a\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/474\/f3b\/e8f\/474f3be8f1765a4214164e61937336d2.png\" width=\"3168\" height=\"768\"><figcaption><\/figcaption><\/figure>\n<p>\u0412\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c \u0443\u0436\u0435 \u0434\u043e\u0433\u0430\u0434\u0430\u043b\u0441\u044f, \u0447\u0442\u043e \u0436\u0435 \u0442\u0443\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442. \u041a\u0430\u043a \u043c\u044b \u0437\u043d\u0430\u0435\u043c, \u0432 Elixir&#8217;e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u043e\u0431\u0449\u0430\u044e\u0442\u0441\u044f \u0434\u0440\u0443\u0433 \u0441 \u0434\u0440\u0443\u0433\u043e\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u043e\u0441\u044b\u043b\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 (message passing). \u0412\u044b\u0437\u043e\u0432\u044b <code>GenServer.call<\/code> \u0438 <code>GenServer.cast<\/code> \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0435\u0431\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043a\u043e\u0440\u0442\u0435\u0436\u0438 \u0441 \u043a\u043b\u044e\u0447\u0430\u043c\u0438 <code>:\"$gen_call\"<\/code>, <code>:\"$gen_cast\"<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043e\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443 GenServer&#8217;\u0430. \u0417\u0430\u0442\u0435\u043c, \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 pattern matching, receive loop \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 GenServer&#8217;\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0432\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u043b\u043b\u0431\u0435\u043a. \u041e\u043f\u0443\u0441\u0442\u0438\u043c \u043d\u0435 \u0432\u0430\u0436\u043d\u044b\u0435 \u043d\u0430\u043c \u0441\u0435\u0439\u0447\u0430\u0441 \u0434\u0435\u0442\u0430\u043b\u0438. \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u044d\u0442\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"erlang\">def loop(state) do   receive msg do     {:\"$gen_call\", {from, ref}, msg} -&gt;       callback_result = handle_call(msg, from, state)       # handle callback result, maybe reply to the client process, call loop again      {:\"$gen_cast\", {from, ref}, msg} -&gt;       callback_result = handle_call(msg, from, state)       # handle callback result, call loop again   end end<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 <code>handle_cast(:run_receive_loop, state)<\/code> \u043a\u043e\u043b\u043b\u0431\u0435\u043a \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 receive loop \u0438 \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 <code>:\"$gen_call\"<\/code> \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u0430\u0434\u0440\u0435\u0441\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0432\u043d\u0435\u0448\u043d\u0435\u043c\u0443 receive loop&#8217;\u0443 \u0441\u0430\u043c\u043e\u0433\u043e GenServer&#8217;\u0430. \u0412 \u0438\u0442\u043e\u0433\u0435 <code>handle_call<\/code> \u043a\u043e\u043b\u043b\u0431\u044d\u043a \u043d\u0435 \u043e\u0442\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442, \u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043a\u0440\u0430\u0448\u0438\u0442\u0441\u044f \u043f\u043e \u0442\u0430\u0439\u043c\u0430\u0443\u0442 (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 5000 ms), \u0442\u0430\u043a \u0438 \u043d\u0435 \u0434\u043e\u0436\u0434\u0430\u0432\u0448\u0438\u0441\u044c \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430 \u0441\u0432\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 <code>SimpleKeyValue.get(pid, :foo)<\/code>.<\/p>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0437 \u0436\u0438\u0437\u043d\u0438<\/h3>\n<p>\u041c\u044b \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0438, \u0447\u0442\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 receive loop \u2014 \u043d\u0435 \u0441\u0430\u043c\u0430\u044f \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u0438\u0434\u0435\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043a \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0438 \u0442\u0440\u0443\u0434\u043d\u043e\u0443\u043b\u043e\u0432\u0438\u043c\u044b\u043c \u0431\u0430\u0433\u0430\u043c. \u0421 \u043e\u0434\u043d\u0438\u043c \u0438\u0437 \u043d\u0438\u0445 \u043c\u043d\u0435 \u043a\u0430\u043a-\u0442\u043e \u0438 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0431\u043e\u0440\u043e\u0442\u044c\u0441\u044f.<\/p>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435, \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u043b receive loop \u0432 \u043a\u043e\u043b\u043b\u0431\u0435\u043a\u0435 \u0432 \u044f\u0432\u043d\u043e\u043c \u0432\u0438\u0434\u0435. \u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432\u0441\u0451 \u043e\u0431\u044b\u0447\u043d\u043e \u0441\u043a\u0440\u044b\u0442\u043e \u0437\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0441\u043b\u043e\u044f\u043c\u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0439.<\/p>\n<p>\u041d\u0430 \u043e\u0434\u043d\u043e\u043c \u043b\u0435\u0433\u0430\u0441\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 HTTP \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430\u0441\u044c <code>tesla<\/code> \u043f\u043e\u0432\u0435\u0440\u0445 <code>mint<\/code>. \u041f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0432 error \u043b\u043e\u0433\u0430\u0445 \u043f\u0440\u043e\u0441\u043a\u0430\u043a\u0438\u0432\u0430\u043b\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432\u0438\u0434\u0430 <code>Encounter unknown error<\/code>, \u0438\u043d\u043e\u0433\u0434\u0430 \u043f\u043e\u0441\u043b\u0435 \u043d\u0438\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043a\u0440\u0430\u0448\u0438\u043b\u0430\u0441\u044c. \u0412 \u043e\u0431\u0449\u0435\u043c, \u0431\u0430\u0433 \u0431\u044b\u043b \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0438\u0439 \u0438 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u044b\u0439.<\/p>\n<p>\u0413\u0440\u0435\u043f\u043d\u0443\u0432 \u043a\u043e\u0434, \u044f \u043d\u0430\u0448\u0451\u043b \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435 \u0432 \u043a\u043e\u0434\u0435 \u0442\u0435\u0441\u043b\u043e\u0432\u0441\u043a\u043e\u0433\u043e \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430 \u043a <code>mint<\/code>&#8216;\u0443:<\/p>\n<pre><code class=\"erlang\">defp stream_response(conn, opts, response \\\\ %{}) do   receive do     msg -&gt;       case HTTP.stream(conn, msg) do         {:ok, conn, stream} -&gt; ...          {:error, _conn, error, _res} -&gt; ...          :unknown -&gt;           {:error, \"Encounter unknown error\"}       end   after     opts |&gt; Keyword.get(:adapter) |&gt; Keyword.get(:timeout) -&gt;       {:error, \"Response timeout\"}   end end<\/code><\/pre>\n<p>\u0423 \u043c\u0435\u043d\u044f \u0437\u0430\u043a\u0440\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u0434\u043e\u0437\u0440\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 receive loop \u043c\u043e\u0433 \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0442\u044c &#171;\u0447\u0443\u0436\u0438\u0435&#187; \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u0438 \u043d\u0435 \u0440\u0430\u0441\u043f\u0430\u0440\u0441\u0438\u0432 \u0438\u0445 \u043a\u0430\u043a \u0432\u0430\u043b\u0438\u0434\u043d\u044b\u0435 HTTP \u043e\u0442\u0432\u0435\u0442\u044b, \u0441\u0432\u0430\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0432 <code>:unknown<\/code> clause. \u041f\u043e\u0442\u0440\u0430\u0442\u0438\u0432 \u0435\u0449\u0451 \u043a\u0430\u043a\u043e\u0435-\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u043f\u043e\u0438\u0441\u043a, \u044f \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b, \u0447\u0442\u043e \u0432 \u043a\u043e\u043b\u043b\u0431\u0435\u043a\u0435 \u043e\u0434\u043d\u043e\u0433\u043e GenServer&#8217;\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u0441\u044f HTTP \u0437\u0430\u043f\u0440\u043e\u0441. \u0412 \u0438\u0442\u043e\u0433\u0435 \u0447\u0435\u0440\u0435\u0437 \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0432\u044b\u0448\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 receive loop \u0438\u0437 <code>stream_response\/3<\/code> \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u043b\u0441\u044f \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432 \u043a\u043e\u043b\u043b\u0431\u0435\u043a\u0435 \u0438 \u0438\u043d\u043e\u0433\u0434\u0430 \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u043b \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u0430\u0434\u0440\u0435\u0441\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e GenServer&#8217;\u0443 \u2014 \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0430\u043b \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0442 \u0441\u043e\u043a\u0435\u0442\u0430. \u0412 \u043e\u0431\u0449\u0435\u043c, \u0432\u0441\u0451 \u043a\u0430\u043a \u044f \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u043b \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435.<\/p>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 HTTP \u0437\u0430\u043f\u0440\u043e\u0441 \u043c\u044b \u043e\u0431\u0435\u0440\u043d\u0443\u043b\u0438 \u0432 Task, \u0447\u0442\u043e\u0431\u044b receive loop \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u0441\u044f \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430, \u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u043b\u0430\u0441\u044c:<\/p>\n<pre><code class=\"erlang\">def handle_call(msg, from, state) do   task = Task.async(fn -&gt; HTTPClient.get_something() end)    case Task.await(task) do     {:ok, data} -&gt;       # handle data      {:error, reason} -&gt;       # handle error case (logging, etc)   end      # ... end<\/code><\/pre>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u041f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 receive loop, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0437\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c\u0438 <code>GenServer.call<\/code> \u0438 <code>GenServer.cast<\/code>\u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044b\u0447\u043d\u0430\u044f \u043f\u043e\u0441\u044b\u043b\u043a\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443 GenServer&#8217;\u0430 \u043f\u043e\u043c\u043e\u0433\u043b\u0438 \u043d\u0430\u043c \u043e\u0442\u043b\u043e\u0432\u0438\u0442\u044c \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u044b\u0439 \u0431\u0430\u0433 \u0438 \u0432\u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0431\u043e\u043b\u0435\u0435 \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c.<\/p>\n<p>\u042f \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u044d\u0442\u0430 \u0438\u0441\u0442\u043e\u0440\u0438\u044f \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u0432\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0439 \u0438 \u043f\u043e\u0443\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439. \u0410 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u043e\u0442\u043a\u0440\u044b\u043b\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044e\u044e \u043a\u0443\u0445\u043d\u044e Elixir&#8217;\u0430 \u0438 Erlang&#8217;\u0430.<\/p>\n<p>\u0412\u0441\u0435\u043c \u0434\u043e\u0431\u0440\u0430 \u0438 \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435!<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/karuna\/blog\/564736\/\"> https:\/\/habr.com\/ru\/company\/karuna\/blog\/564736\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0418\u0432\u0430\u043d, \u044f \u2014&nbsp;\u0442\u0435\u0445\u043b\u0438\u0434 \u0432 \u041a\u0430\u0440\u0443\u043d\u0435.<\/p>\n<p>\u0412 \u043a\u043e\u043c\u0430\u043d\u0434\u0435 \u043c\u044b \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Elixir \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u043d\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432.<\/p>\n<p>\u041c\u044b \u0443\u0434\u0435\u043b\u044f\u0435\u043c \u043e\u0441\u043e\u0431\u043e\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0437\u0430 \u043a\u043e\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u043b\u043b\u0431\u0435\u043a\u0430\u0445 GenServer&#8217;\u0430, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043a\u043e\u0434 \u0442\u0440\u0435\u0442\u044c\u0435\u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043f\u043e\u0447\u0435\u043c\u0443 \u044d\u0442\u043e \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0436\u043d\u043e, \u0438 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e, \u043a\u0430\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0445 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u043d\u0430\u043c Elixir \u0438 Erlang, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043b\u043e\u043c\u0430\u0442\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 GenServer&#8217;a \u0438 \u043f\u043e\u0440\u043e\u0434\u0438\u0442\u044c \u0442\u0440\u0443\u0434\u043d\u043e\u0443\u043b\u043e\u0432\u0438\u043c\u044b\u0435 \u0431\u0430\u0433\u0438. \u0415\u0449\u0451 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u043c\u044b \u0431\u043e\u0440\u043e\u043b\u0438\u0441\u044c \u0441 \u0442\u0430\u043a\u0438\u043c \u0431\u0430\u0433\u043e\u043c \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0436\u0438\u0437\u043d\u0438.<\/p>\n<p>\u041f\u043e\u0435\u0445\u0430\u043b\u0438!<\/p>\n<h3>Key-value \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435<\/h3>\n<p>\u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430. \u0410\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044f GenServer&#8217;\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0439 \u0432 Erlang\/OTP \u0438 Elixir. \u041f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0430\u0431\u043e\u0442\u044b GenServer&#8217;\u0430 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442.<\/p>\n<p>\u042d\u0442\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0445\u0440\u0430\u043d\u0438\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u0438\u0437\u043c\u0435\u043d\u044f\u044f \u044d\u0442\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043f\u043e\u0441\u044b\u043b\u0430\u044f \u043e\u0442\u0432\u0435\u0442\u043d\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f.<\/p>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u0442\u043e\u043d\u043a\u043e\u0441\u0442\u044f\u043c \u0440\u0430\u0431\u043e\u0442\u044b GenServer&#8217;\u0430, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043e\u0434\u0438\u043d \u0438\u0437 \u043d\u0438\u0445.<\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u043e\u0435 key-value \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438 \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u043a\u043b\u044e\u0447\u0443.<\/p>\n<p>\u041d\u0438\u0447\u0435\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e: \u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 GenServer&#8217;\u0430 \u0432\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435 \u0441\u0442\u0430\u0442\u0435\u0439 \u0438 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u043e\u0432.<\/p>\n<pre><code class=\"erlang\">defmodule SimpleKeyValue do   use GenServer    def start do     GenServer.start(__MODULE__, %{})   end    def put(pid, key, value) do     GenServer.cast(pid, {:put, key, value})   end    def get(pid, key) do     GenServer.call(pid, {:get, key})   end    # Callbacks   @impl true   def init(state) do     {:ok, state}   end    @impl true   def handle_cast({:put, key, value}, state) do     {:noreply, Map.put(state, key, value)}   end    @impl true   def handle_call({:get, key}, _from, state) do     {:reply, Map.fetch!(state, key), state}   end end<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438. \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043a\u0430\u043a \u0437\u0430\u0434\u0443\u043c\u0430\u043d\u043e. \u041c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438 \u0441\u043c\u043e\u0433\u043b\u0438 \u0432\u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0435\u0433\u043e \u043f\u043e \u043a\u043b\u044e\u0447\u0443<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h3>\u041b\u043e\u043c\u0430\u0435\u043c GenServer<\/h3>\n<p>\u041f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u0443\u0437\u043d\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0435\u0442\u0430\u043b\u0438 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0439 \u043a\u0443\u0445\u043d\u0438 GenServer&#8217;a.<\/p>\n<p>\u042f \u0441\u0447\u0438\u0442\u0430\u044e, \u0447\u0442\u043e \u043e\u0434\u0438\u043d \u0438\u0437 \u043b\u0443\u0447\u0448\u0438\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u0447\u0442\u043e-\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u2014 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u0447\u0442\u043e-\u0442\u043e \u0441\u043b\u043e\u043c\u0430\u0442\u044c.<\/p>\n<p>\u0410 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u0441\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0441 \u043d\u0430\u0448\u0438\u043c GenServer&#8217;\u043e\u043c, \u0435\u0441\u043b\u0438 \u0432 \u043a\u043e\u043b\u043b\u0431\u044d\u043a\u0435 \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 receive loop:<\/p>\n<pre><code class=\"erlang\">def run_receive_loop(server) do   GenServer.cast(server, :run_receive_loop) end  @impl true def handle_cast(:run_receive_loop, state) do   receive do     msg -&gt; IO.inspect(msg, label: \"RECEIVE LOOP\")   end    {:noreply, state} end<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0451\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u0430\u043a\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c \u0443\u0436\u0435 \u0434\u043e\u0433\u0430\u0434\u0430\u043b\u0441\u044f, \u0447\u0442\u043e \u0436\u0435 \u0442\u0443\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442. \u041a\u0430\u043a \u043c\u044b \u0437\u043d\u0430\u0435\u043c, \u0432 Elixir&#8217;e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u043e\u0431\u0449\u0430\u044e\u0442\u0441\u044f \u0434\u0440\u0443\u0433 \u0441 \u0434\u0440\u0443\u0433\u043e\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u043e\u0441\u044b\u043b\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 (message passing). \u0412\u044b\u0437\u043e\u0432\u044b <code>GenServer.call<\/code> \u0438 <code>GenServer.cast<\/code> \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0435\u0431\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043a\u043e\u0440\u0442\u0435\u0436\u0438 \u0441 \u043a\u043b\u044e\u0447\u0430\u043c\u0438 <code>:\"$gen_call\"<\/code>, <code>:\"$gen_cast\"<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043e\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443 GenServer&#8217;\u0430. \u0417\u0430\u0442\u0435\u043c, \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 pattern matching, receive loop \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 GenServer&#8217;\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0432\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u043b\u043b\u0431\u0435\u043a. \u041e\u043f\u0443\u0441\u0442\u0438\u043c \u043d\u0435 \u0432\u0430\u0436\u043d\u044b\u0435 \u043d\u0430\u043c \u0441\u0435\u0439\u0447\u0430\u0441 \u0434\u0435\u0442\u0430\u043b\u0438. \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u044d\u0442\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"erlang\">def loop(state) do   receive msg do     {:\"$gen_call\", {from, ref}, msg} -&gt;       callback_result = handle_call(msg, from, state)       # handle callback result, maybe reply to the client process, call loop again      {:\"$gen_cast\", {from, ref}, msg} -&gt;       callback_result = handle_call(msg, from, state)       # handle callback result, call loop again   end end<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 <code>handle_cast(:run_receive_loop, state)<\/code> \u043a\u043e\u043b\u043b\u0431\u0435\u043a \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 receive loop \u0438 \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 <code>:\"$gen_call\"<\/code> \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u0430\u0434\u0440\u0435\u0441\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0432\u043d\u0435\u0448\u043d\u0435\u043c\u0443 receive loop&#8217;\u0443 \u0441\u0430\u043c\u043e\u0433\u043e GenServer&#8217;\u0430. \u0412 \u0438\u0442\u043e\u0433\u0435 <code>handle_call<\/code> \u043a\u043e\u043b\u043b\u0431\u044d\u043a \u043d\u0435 \u043e\u0442\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442, \u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043a\u0440\u0430\u0448\u0438\u0442\u0441\u044f \u043f\u043e \u0442\u0430\u0439\u043c\u0430\u0443\u0442 (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 5000 ms), \u0442\u0430\u043a \u0438 \u043d\u0435 \u0434\u043e\u0436\u0434\u0430\u0432\u0448\u0438\u0441\u044c \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430 \u0441\u0432\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 <code>SimpleKeyValue.get(pid, :foo)<\/code>.<\/p>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0437 \u0436\u0438\u0437\u043d\u0438<\/h3>\n<p>\u041c\u044b \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0438, \u0447\u0442\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 receive loop \u2014 \u043d\u0435 \u0441\u0430\u043c\u0430\u044f \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u0438\u0434\u0435\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043a \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0438 \u0442\u0440\u0443\u0434\u043d\u043e\u0443\u043b\u043e\u0432\u0438\u043c\u044b\u043c \u0431\u0430\u0433\u0430\u043c. \u0421 \u043e\u0434\u043d\u0438\u043c \u0438\u0437 \u043d\u0438\u0445 \u043c\u043d\u0435 \u043a\u0430\u043a-\u0442\u043e \u0438 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0431\u043e\u0440\u043e\u0442\u044c\u0441\u044f.<\/p>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435, \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u043b receive loop \u0432 \u043a\u043e\u043b\u043b\u0431\u0435\u043a\u0435 \u0432 \u044f\u0432\u043d\u043e\u043c \u0432\u0438\u0434\u0435. \u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432\u0441\u0451 \u043e\u0431\u044b\u0447\u043d\u043e \u0441\u043a\u0440\u044b\u0442\u043e \u0437\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0441\u043b\u043e\u044f\u043c\u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0439.<\/p>\n<p>\u041d\u0430 \u043e\u0434\u043d\u043e\u043c \u043b\u0435\u0433\u0430\u0441\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 HTTP \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430\u0441\u044c <code>tesla<\/code> \u043f\u043e\u0432\u0435\u0440\u0445 <code>mint<\/code>. \u041f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0432 error \u043b\u043e\u0433\u0430\u0445 \u043f\u0440\u043e\u0441\u043a\u0430\u043a\u0438\u0432\u0430\u043b\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432\u0438\u0434\u0430 <code>Encounter unknown error<\/code>, \u0438\u043d\u043e\u0433\u0434\u0430 \u043f\u043e\u0441\u043b\u0435 \u043d\u0438\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043a\u0440\u0430\u0448\u0438\u043b\u0430\u0441\u044c. \u0412 \u043e\u0431\u0449\u0435\u043c, \u0431\u0430\u0433 \u0431\u044b\u043b \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0438\u0439 \u0438 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u044b\u0439.<\/p>\n<p>\u0413\u0440\u0435\u043f\u043d\u0443\u0432 \u043a\u043e\u0434, \u044f \u043d\u0430\u0448\u0451\u043b \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435 \u0432 \u043a\u043e\u0434\u0435 \u0442\u0435\u0441\u043b\u043e\u0432\u0441\u043a\u043e\u0433\u043e \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430 \u043a <code>mint<\/code>&#8216;\u0443:<\/p>\n<pre><code class=\"erlang\">defp stream_response(conn, opts, response \\\\ %{}) do   receive do     msg -&gt;       case HTTP.stream(conn, msg) do         {:ok, conn, stream} -&gt; ...          {:error, _conn, error, _res} -&gt; ...          :unknown -&gt;           {:error, \"Encounter unknown error\"}       end   after     opts |&gt; Keyword.get(:adapter) |&gt; Keyword.get(:timeout) -&gt;       {:error, \"Response timeout\"}   end end<\/code><\/pre>\n<p>\u0423 \u043c\u0435\u043d\u044f \u0437\u0430\u043a\u0440\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u0434\u043e\u0437\u0440\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 receive loop \u043c\u043e\u0433 \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0442\u044c &#171;\u0447\u0443\u0436\u0438\u0435&#187; \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u0438 \u043d\u0435 \u0440\u0430\u0441\u043f\u0430\u0440\u0441\u0438\u0432 \u0438\u0445 \u043a\u0430\u043a \u0432\u0430\u043b\u0438\u0434\u043d\u044b\u0435 HTTP \u043e\u0442\u0432\u0435\u0442\u044b, \u0441\u0432\u0430\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0432 <code>:unknown<\/code> clause. \u041f\u043e\u0442\u0440\u0430\u0442\u0438\u0432 \u0435\u0449\u0451 \u043a\u0430\u043a\u043e\u0435-\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u043f\u043e\u0438\u0441\u043a, \u044f \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b, \u0447\u0442\u043e \u0432 \u043a\u043e\u043b\u043b\u0431\u0435\u043a\u0435 \u043e\u0434\u043d\u043e\u0433\u043e GenServer&#8217;\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u0441\u044f HTTP \u0437\u0430\u043f\u0440\u043e\u0441. \u0412 \u0438\u0442\u043e\u0433\u0435 \u0447\u0435\u0440\u0435\u0437 \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0432\u044b\u0448\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 receive loop \u0438\u0437 <code>stream_response\/3<\/code> \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u043b\u0441\u044f \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432 \u043a\u043e\u043b\u043b\u0431\u0435\u043a\u0435 \u0438 \u0438\u043d\u043e\u0433\u0434\u0430 \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u043b \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u0430\u0434\u0440\u0435\u0441\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e GenServer&#8217;\u0443 \u2014 \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0430\u043b \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0442 \u0441\u043e\u043a\u0435\u0442\u0430. \u0412 \u043e\u0431\u0449\u0435\u043c, \u0432\u0441\u0451 \u043a\u0430\u043a \u044f \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u043b \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435.<\/p>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 HTTP \u0437\u0430\u043f\u0440\u043e\u0441 \u043c\u044b \u043e\u0431\u0435\u0440\u043d\u0443\u043b\u0438 \u0432 Task, \u0447\u0442\u043e\u0431\u044b receive loop \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u0441\u044f \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430, \u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u043b\u0430\u0441\u044c:<\/p>\n<pre><code class=\"erlang\">def handle_call(msg, from, state) do   task = Task.async(fn -&gt; HTTPClient.get_something() end)    case Task.await(task) do     {:ok, data} -&gt;       # handle data      {:error, reason} -&gt;       # handle error case (logging, etc)   end      # ... end<\/code><\/pre>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u041f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 receive loop, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0437\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c\u0438 <code>GenServer.call<\/code> \u0438 <code>GenServer.cast<\/code>\u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044b\u0447\u043d\u0430\u044f \u043f\u043e\u0441\u044b\u043b\u043a\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443 GenServer&#8217;\u0430 \u043f\u043e\u043c\u043e\u0433\u043b\u0438 \u043d\u0430\u043c \u043e\u0442\u043b\u043e\u0432\u0438\u0442\u044c \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u044b\u0439 \u0431\u0430\u0433 \u0438 \u0432\u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0431\u043e\u043b\u0435\u0435 \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c.<\/p>\n<p>\u042f \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u044d\u0442\u0430 \u0438\u0441\u0442\u043e\u0440\u0438\u044f \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u0432\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0439 \u0438 \u043f\u043e\u0443\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439. \u0410 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u043e\u0442\u043a\u0440\u044b\u043b\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044e\u044e \u043a\u0443\u0445\u043d\u044e Elixir&#8217;\u0430 \u0438 Erlang&#8217;\u0430.<\/p>\n<p>\u0412\u0441\u0435\u043c \u0434\u043e\u0431\u0440\u0430 \u0438 \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435!<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/karuna\/blog\/564736\/\"> https:\/\/habr.com\/ru\/company\/karuna\/blog\/564736\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-325678","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/325678","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=325678"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/325678\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=325678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=325678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=325678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}