The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Coro::ProcessPool::Pipeline

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 Coro::ProcessPool::process and Coro::ProcessPool::defer.

shutdown

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