GitHub Viewer
// This program demonstrates how to use tf::DataPipeline to create
// a pipeline with in-pipe data automatically managed by the Taskflow
// library.
#include
#include
int main() {
// dataflow => void -> int -> std::string -> float -> void
tf::Taskflow taskflow("pipeline");
tf::Executor executor;
const size_t num_lines = 3;
// create a pipeline graph
tf::DataPipeline pl(num_lines,
tf::make_data_pipe(tf::PipeType::SERIAL, [&](tf::Pipeflow& pf) -> int{
if(pf.token() == 5) {
pf.stop();
return 0;
}
else {
printf("first pipe returns %lu\n", pf.token());
return pf.token();
}
}),
tf::make_data_pipe(tf::PipeType::SERIAL, [](int& input) {
printf("second pipe returns a strong of %d\n", input + 100);
return std::to_string(input + 100);
}),
tf::make_data_pipe(tf::PipeType::SERIAL, [](std::string& input) {
printf("third pipe receives the input string %s\n", input.c_str());
})
);
// build the pipeline graph using composition
taskflow.composed_of(pl).name("pipeline");
// dump the pipeline graph structure (with composition)
taskflow.dump(std::cout);
// run the pipeline
executor.run(taskflow).wait();
return 0;
}