     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


    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])

    snakes = for {:ok, snake} <- stream, do: snake


alias Bs.Snake
alias Bs.World
alias Bs.World.Factory.Worker

defmodule Bs.World.Factory do
  @new_snake_length 3

  def build(game_form) do
