Parallelise arbitrary tasks in a controlled way.
taskforce runs a group of independent tasks concurrently, bounding both the
number of workers and how long execution may take, and gathers their results.
Build tasks with task/3, then run them with execute/1 or execute/2. See
the README for an overview and examples.
Summary
Functions
Run Tasks concurrently with default execution options.
Run Tasks concurrently, subject to ExecutionOptions.
Create a task that runs Function applied to Args.
Types
-type execution_options() :: #{timeout => pos_integer(), max_workers => pos_integer()}.
-opaque task()
-type task_settings() :: #{timeout := pos_integer()}.
Functions
Run Tasks concurrently with default execution options.
Equivalent to execute(Tasks, #{}).
-spec execute(Tasks, ExecutionOptions) -> Result when Tasks :: tasks(), ExecutionOptions :: execution_options(), Result :: result().
Run Tasks concurrently, subject to ExecutionOptions.
ExecutionOptions may bound the global timeout (in milliseconds) and the
maximum number of concurrent workers (max_workers); both default sensibly when
omitted. Returns the tasks that completed, along with the ids of those that
hit an individual_timeouts or a global_timeouts.
-spec task(Function, Args, TaskSettings) -> Task when Function :: fun(), Args :: [term()], TaskSettings :: task_settings(), Task :: task().
Create a task that runs Function applied to Args.
TaskSettings must contain a timeout, in milliseconds, bounding how long the
individual task may run before being given up on.