snowhite v2.1.3 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
Specs
option() :: {:map_after, function()}
Specs
Link to this section Functions
Specs
run([task_definition(any())], [option()]) :: [{any(), any()}]
Runs multiple tasks concurrently and returns once they all done.
Following options are supported:
map_after
(function
, fallbacks to identity function): Runs the function on the await's result to map over the result of the task.
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
iex> map_after = fn v -> v / 1000 end
iex> TaskRunner.run([
{:first, fn ->
:timer.sleep(1000)
{:done, 1000}
end},
{:first, fn ms ->
:timer.sleep(ms)
{:done, ms}
end, [2000]}
], map_after)
[{:first, {:done, 1}}, {:second, {:done, 2}}] # after 2000ms