Bounded Elixir worker pool via Task.async_stream

Elixir
defmodule WorkerPool do
  def run(items, worker, size \\ 4) when is_function(worker, 1) and size > 0 do
    items
    |> Task.async_stream(worker,
      max_concurrency: size,
      timeout: :infinity
    )
    |> Enum.map(fn
      {:ok, value} -> {:ok, value}
      {:exit, reason} -> {:error, reason}
    end)
  end
end