ovo_utils v0.1.0 OvoUtils.ConcurrentTasks View Source
Utility functions for common tasks involving concurrent tasks.
Link to this section Summary
Functions
Concurrently executes functions and returns the results in a map
Link to this section Functions
Link to this function
populate_map_with_concurrent_functions(functions, timeout \\ 5000) View Source
Concurrently executes functions and returns the results in a map.
Expects a list of tuples containing a key and a zero arity function that returns either {:ok, result} or {:error, reason}.
These functions are then executed concurrently and their results are returned together in a map indexed by their keys.
Returns
- {:ok, map} if all functions return an :ok tuple
{:error, reason}, if any function:
- returns an :error tuple
- does not complete before timeout
- exits without returning a value
Examples
iex> ConcurrentTasks
...> .populate_map_with_concurrent_functions([
...> {:key1, fn -> {:ok, 2 + 2} end},
...> {:key2, fn -> {:ok, 2 * 3} end}
...> ])
{:ok, %{key1: 4, key2: 6}}