The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Util::Task::Sequence - A task for running other tasks sequentially.

SYNOPSIS

    my $base_task = Util::Task::Something->new();
    my $task = Util::Task::Sequence->new($base_task, sub {
        my $result = shift;
        return Util::Task::SomethingElse->new($result);
    });

DESCRIPTION

In some cases, a task is actually a sequence of smaller task where each step depends on the previous step. For example, if you want to load a list of items for a user by username, you might first need to translate the username into a userid.

While it is in theory possible to build a single task that does both of these steps, tasks that perform multiple steps are difficult to batch and coalesce.

This class, which is one of the fundamental building blocks of the Util::Task framework and is handled as a special case, allows single tasks to be strung together into a sequence where the result of one feeds into the next.

When sequence tasks are added to a Util::Task::Multi, the execution of the multi-task is split into phases, each of which has its own batching step. Where the constituent tasks support coalescing, the system will also use solutions found in previous phases to avoid repeating work.

USAGE

The constructor for this class takes two arguments. The first is a Util::Task instance that will form the first step in this sequence. The second is a CODE ref that will recieve the result returned by the first step and should return either another Util::Task instance for the second step or undef to indicate that the next step does not need to run and that undef should be returned for this overall task.

The progression function may itself return a Util::Task::Sequence to allow multi-step sequences to be created dynamically.

The return value of a sequence task is the return value of the task returned by the progression function, or undef if the progression function returns undef.