@@ -0,0 +1,34 @@
|
||||
// Example 10 — Static Hello Pipeline
|
||||
//
|
||||
// The same linear pipeline as example 01, built with make_network() instead
|
||||
// of the runtime Network builder. The topology is fully known at compile time:
|
||||
// cycle detection is a static_assert, no build() step is needed, and start/stop
|
||||
// require no virtual dispatch through a string-keyed node map.
|
||||
//
|
||||
// [produce] --int--> [double_it] --int--> [print_it]
|
||||
|
||||
#include <kpn/kpn.hpp>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
static int produce() { return 42; }
|
||||
static int double_it(int x) { return x * 2; }
|
||||
static void print_it(int x) { std::cout << "result: " << x << '\n'; }
|
||||
|
||||
int main() {
|
||||
using namespace kpn;
|
||||
|
||||
auto src = make_node<produce, "src" >(5);
|
||||
auto dbl = make_node<double_it, "dbl" >(5);
|
||||
auto sink = make_node<print_it, "sink">(5);
|
||||
|
||||
auto net = make_network(
|
||||
edge(src.output<0>(), dbl.input<0>()),
|
||||
edge(dbl.output<0>(), sink.input<0>())
|
||||
);
|
||||
|
||||
net.start();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
net.stop();
|
||||
}
|
||||
Reference in New Issue
Block a user