 defmodule Funnel.Transistor do
   @moduledoc """
-  `Funnel.Transistor` can be see as a User. It can have several connections, and
-  will notify a matching document on each of thoses connections.
+  `Funnel.Transistor` can be see as a User. It can have several transports, and
+  will notify a matching document on each of thoses transports.
   """
   use GenServer.Behaviour
   alias Funnel.Transistor.Cache


  @doc """

  Wrapper around `GenServer`. Add a new connection in the connections's pool.

  * `conn`    - Process id
  * `token`   - the token used to identify the connection
  * `last_id` - the last id received in the connection
  """
  def add(conn, token, last_id \\ nil) do
    :gen_server.call name(token), {:add, conn, last_id}
  end

  @doc """

  Default values of `Funnel.Transistor`. An empty pool of connections.
  """
  def init(cache) do
    {:ok, %TransistorState{cache: cache}}

    :gen_server.start_link({:local, name}, __MODULE__, cache, [])
  end

  defp write_from_cache(transport, cache, last_id) do
    Enum.reduce(Cache.list(cache, last_id), transport, fn(item, transport) -> write(transport, item) end)
  end

  defp message(id, item) do
