snowhite v0.1.2 Snowhite.Helpers.TaskRunner View Source

Link to this section Summary

Functions

Runs multiple tasks concurrently and returns once they all done.

Link to this section Types

Link to this type

task_definition(key_type)

View Source

Specs

task_definition(key_type) :: {key_type, function()}

Link to this section Functions

Specs

run([task_definition(any())]) :: [{any(), any()}]

Runs multiple tasks concurrently and returns once they all done.

Examples

iex> alias Snowhite.Helpers.TaskRunner
iex> TaskRunner.run([
  {:first, fn ->
    :timer.sleep(1000)
    {:done, 1000}
  end},
  {:first, fn ms ->
    :timer.sleep(ms)
    {:done, ms}
  end, [2000]}
])
[{:first, {:done, 1000}}, {:second, {:done, 2000}}] # after 2000ms