BusyBird::Flow - CPS data flow with concurrency regulation
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"; });
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.
Creates the flow object.
Add a filter to the $flow.
$flow
When $flow is executed, $filter is called like
execute
$filter
$filter->($data, $done)
When $filter finishes its job, it is supposed to call $done with the result of the filter.
$done
$done->($result)
Execute the flow on the $data.
$data
When the flow ends, the result will be given to $finish_callback as in
$finish_callback
$finish_callback->($result)
Toshio Ito <toshioito [at] cpan.org>
<toshioito [at] cpan.org>
To install BusyBird, copy and paste the appropriate command in to your terminal.
cpanm
cpanm BusyBird
CPAN shell
perl -MCPAN -e shell install BusyBird
For more information on module installation, please visit the detailed CPAN module installation guide.