title: GenStage: retry handle_demand when GenServer updates
body: <p>If my GenStage's <code>handle_demand/2</code> method looks like this:</p>
  
  <pre><code>def handle_demand(demand, _state) when demand &gt; 0 do
    case Queue.dequeue do
      nil -&gt;
        Logger.debug("Queue empty.")
        {:noreply, [], []}
      {job, updated_queue} -&gt; {:noreply, job, updated_queue}
    end
  end
  </code></pre>
  
  <p>How do I get it to "rerun" when my <code>Queue</code> (a GenServer) is changed/updated?</p>
  
  <p>My queue module just looks like this:</p>
  
  <pre><code>defmodule Queue do
    use GenServer
  
    ### client
  
    def start_link(state \\ []) do
      GenServer.start_link(__MODULE__, state, name: __MODULE__)
    end
  
    def queue, do: GenServer.call(__MODULE__, :queue)
  
    def enqueue(value), do: GenServer.cast(__MODULE__, {:enqueue, value})
  
    def dequeue, do: GenServer.call(__MODULE__, :dequeue)
  
    ### server
  
    def init(state), do: {:ok, state}
  
    def handle_call(:dequeue, _from, [value | state]) do
      {:reply, value, state}
    end
  
    def handle_call(:dequeue, _from, []), do: {:reply, nil, []}
  
    def handle_call(:queue, _from, state), do: {:reply, state, state}
  
    def handle_cast({:enqueue, value}, state) do
      {:noreply, state ++ [value]}
    end
  end
  </code></pre>