title: How to call other functions from within Elixir GenServer handler?
body: <p>I have a GenServer that implements functionality for a single item, e.g:</p>
  
  <pre><code>def handle_call({:sync, id}, _from, state) do
      ## update data
      {:reply, data, sync}
  end
  </code></pre>
  
  <p>Now I want to handle this functionality for multiple ids, e.g.:</p>
  
  <pre><code>def handle_call({:sync_all, ids}, _from, state) do
      ## call sync for each id
      data = Enum.map(ids, fn(id) -&gt;
          GenServer.call(self(), {:sync, id})
      end)
      ## Further reduce down data to stats
      {:reply, data, sync}
  end
  </code></pre>
  
  <p>This however does not work telling me that the process attempted to call itself.</p>
  
  <p>I assume this must be due to the blocking nature of <code>call</code>. The same however happens if I use <code>cast</code> in the <code>sync_all</code> version.</p>
  
  <p>So my question is: How can I call other <code>GenServer</code> tasks from within a <code>handle_call</code> or <code>handle_cast</code> function?</p>