Parallel-TaskExecutor

 view release on metacpan or  search on metacpan

lib/Parallel/TaskExecutor.pm  view on Meta::CPAN


B<untracked>: if set to true, the task will not increase the number of running
task counted by the executor. However, the call to run() might still be blocked
if the number of outstanding tasks exceeds B<max_parallel_tasks> (unless
B<forced> is set to true too).

=back

=cut

Readonly::Scalar my $busy_loop_wait_time_us => 1000;

sub run {
  my ($this, $sub, %options) = @_;
  %options = (%{$this->{options}}, %options);
  # TODO: add an option to always call _remove_done_tasks here, to cleanup.
  while (!$options{forced} && $this->{current_tasks} >= $this->{max_parallel_tasks}) {
    $this->_remove_done_tasks();
    usleep($busy_loop_wait_time_us);
  }
  return $this->_fork_and_run($sub, %options);
}

=pod

=head2 run_now()

  my $data = $executor->run_now($sub, %options);



( run in 0.294 second using v1.01-cache-2.11-cpan-87723dcf8b7 )