NAME

Coro::ProcessPool::Pipeline - A producer/consumer pipeline for Coro::ProcessPool

VERSION

version 0.30

SYNOPSIS

my $pool = Coro::ProcesPool->new();
my $pipe = $pool->pipeline;

# Start producer thread to queue tasks
my $producer = async {
  while (my $task = get_next_task()) {
    $pipe->queue('Some::TaskClass', $task);
  }

  # Let the pipeline know no more tasks are coming
  $pipe->shutdown;
};

# Collect the results of each task as they are received
while (my $result = $pipe->next) {
  do_stuff_with($result);
}

DESCRIPTION

Provides an iterative mechanism for feeding tasks into the process pool and collecting results. A pool may have multiple pipelines.

ATTRIBUTES

pool (required)

The Coro::ProcessPool in which to queue tasks.

auto_shutdown (default: false)

When set to true, the pipeline will shut itself down as soon as the number of pending tasks hits zero. At least one task must be sent for this to be triggered.

METHODS

next

Cedes control until a previously queued task is complete and the result is available.

queue($task, $args)

Queues a new task. Arguments are identical to "process" in Coro::ProcessPool and "defer" in Coro::ProcessPool.

shutdown

Signals shutdown of the pipeline. A shutdown pipeline may not be reused.

AUTHOR

Jeff Ober <sysread@fastmail.fm>

COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by Jeff Ober.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.