 
     snakes = game_form.snakes
 
-    task = fn snake_form ->
-      url = snake_form.url
-      url = "#{url}/start"
-
-      response = HTTPoison.post!(
-        url,
-        data,
-        ["content-type": "application/json"],
-        [recv_timeout: @timeout]
-      )
-
-      json = Poison.decode! response.body
-
-      model = %Snake{
-        url: snake_form.url,
-        id: snake_form.id,
-      }
-
-      changeset = Snake.changeset(model, json)
-
-      if changeset.valid? do
-        Ecto.Changeset.apply_changes changeset
-      else
-        raise changeset.errors
-      end
-    end
-
-    stream = Task.async_stream(snakes, task, [timeout: @timeout])
+    stream = Task.async_stream(
+      snakes,
+      Worker,
+      :run,
+      [data]
+    )
 
     snakes = for {:ok, snake} <- stream, do: snake
 

defmodule Bs.World.Factory do
  alias Bs.Snake
  alias Bs.World

  @timeout 200
  @new_snake_length 3

  def build(game_form) do

    end
  end
end

defmodule Bs.World.Factory.Worker do
  @timeout 1000

  def run(permalink, opts \\ [])
  def run(%{id: id, url: url}, data) do
    start_url = url <> "/start"

    response = HTTPoison.post!(
      start_url,
      data,
      ["content-type": "application/json"],
      [recv_timeout: @timeout]
    )

    json = Poison.decode! response.body

    model = %Snake{
      url: url,
      id: id,
    }

    changeset = Snake.changeset(model, json)

    if changeset.valid? do
      Ecto.Changeset.apply_changes changeset
    else
      raise changeset.errors
    end
  end
end
