Current section
Files
Jump to
Current section
Files
lib/concurrent.ex
defmodule Concurrent do
@moduledoc """
Enum with concurrency by using Elixir Task
"""
@doc """
Hello world.
## Examples
iex> Concurrent.map([1, 2, 3], & &1 * &1)
[1, 4, 9]
"""
def map(enum, fun, options \\ [timeout: 5_000]) do
enum
|> Enum.map(&Task.async(fn -> fun.(&1) end))
|> Enum.map(&Task.await(&1, options[:timeout]))
end
end