NAME

BusyBird::Flow - CPS data flow with concurrency regulation

SYNOPSIS

    use BusyBird::Flow;
    
    my $flow = BusyBird::Flow->new();
    
    $flow->add(sub {
        my ($data, $done) = @_;
        my $new_data = transform($data);
        $done->($new_data);
    });
    
    $flow->add(sub {
        my ($data, $done) = @_;
        transform_async($data, sub {
            my $new_data = shift;
            $done->($new_data);
        });
    });
    
    $flow->execute('some_data', sub {
        my ($result_data) = @_;
        print "Result: $result_data\n";
    });

DESCRIPTION

This module is a part of BusyBird::Timeline. For now, it is not meant to be used individually.

This module takes CPS (continuation-passing style) subroutines as "filters" and executes them sequentially to a given data. The result of a filter is given to the next filter, so the data flow is so-called "waterfall" model.

In the data flow, the number of data flowing simultaneously is limited. If additional data is pushed to the flow, it will be delayed in a queue that is built in the flow.

This module uses BusyBird::Log for logging.

CLASS METHODS

$flow = BusyBird::Flow->new()

Creates the flow object.

OBJECT METHODS

$flow->add($filter)

Add a filter to the $flow.

When $flow is executed, $filter is called like

    $filter->($data, $done)

When $filter finishes its job, it is supposed to call $done with the result of the filter.

    $done->($result)

$flow->execute($data, $finish_callback)

Execute the flow on the $data.

When the flow ends, the result will be given to $finish_callback as in

    $finish_callback->($result)

AUTHOR

Toshio Ito <toshioito [at] cpan.org>