11#include < iostream>
22
3- #include " reactor-cpp/reactor-cpp.hh"
3+ #include < reactor-cpp/reactor-cpp.hh>
44
55using namespace reactor ;
66using namespace std ::chrono_literals;
@@ -38,6 +38,7 @@ class Counter : public Reactor {
3838 Output<int > count{" count" , this }; // NOLINT
3939
4040 void assemble () override {
41+ std::cout << " assemble Counter" << std::endl << std::flush;
4142 r_trigger.declare_trigger (&trigger);
4243 r_trigger.declare_antidependency (&count);
4344 }
@@ -53,12 +54,15 @@ class Printer : public Reactor {
5354 Reaction r_value{" r_value" , 1 , this , [this ]() { on_value (); }};
5455
5556public:
56- Input<int > value{" value" , this }; // NOLINT
57-
57+ Input<int > value{" value" , this }; // NOLINT
58+ Input< int > forward{ " forward " , this }; // NOLINT
5859 Printer (const std::string& name, Environment* env)
5960 : Reactor(name, env) {}
6061
61- void assemble () override { r_value.declare_trigger (&value); }
62+ void assemble () override {
63+ std::cout << " assemble Printer" << std::endl << std::flush;
64+ r_value.declare_trigger (&value);
65+ }
6266
6367 void on_value () { std::cout << this ->name () << " : " << *value.get () << std::endl; }
6468};
@@ -84,6 +88,7 @@ class Adder : public Reactor {
8488 void add () {
8589 if (i1.is_present () && i2.is_present ()) {
8690 sum.set (*i1.get () + *i2.get ());
91+ std::cout << " setting sum" << std::endl;
8792 }
8893 }
8994};
@@ -94,23 +99,31 @@ auto main() -> int {
9499 Trigger trigger1{" t1" , &env, 1s};
95100 Counter counter1{" c1" , &env};
96101 Printer printer1{" p1" , &env};
97- trigger1.trigger .bind_to (&counter1.trigger );
98- counter1.count .bind_to (&printer1.value );
102+
103+ env.draw_connection (trigger1.trigger , counter1.trigger , ConnectionProperties{});
104+ env.draw_connection (counter1.count , printer1.value , ConnectionProperties{});
99105
100106 Trigger trigger2{" t2" , &env, 2s};
101107 Counter counter2{" c2" , &env};
102108 Printer printer2{" p2" , &env};
103- trigger2.trigger .bind_to (&counter2.trigger );
104- counter2.count .bind_to (&printer2.value );
109+
110+ // trigger2.trigger.set_inward_binding(&counter2.trigger);
111+ // counter2.count.set_inward_binding(&printer2.value);
112+ env.draw_connection (trigger2.trigger , counter2.trigger , ConnectionProperties{});
113+ env.draw_connection (counter2.count , printer2.value , ConnectionProperties{});
105114
106115 Adder add{" add" , &env};
107116 Printer p_add{" p_add" , &env};
108- counter1.count .bind_to (&add.i1 );
109- counter2.count .bind_to (&add.i2 );
110- add.sum .bind_to (&p_add.value );
111117
118+ env.draw_connection (counter1.count , add.i1 , ConnectionProperties{});
119+ env.draw_connection (counter2.count , add.i2 , ConnectionProperties{});
120+ env.draw_connection (add.sum , p_add.forward , ConnectionProperties{ConnectionType::Delayed, 10s, nullptr });
121+ env.draw_connection (p_add.forward , p_add.value , ConnectionProperties{ConnectionType::Delayed, 5s, nullptr });
122+
123+ std::cout << " assemble" << std::endl << std::flush;
112124 env.assemble ();
113125
126+ std::cout << " optimize" << std::endl << std::flush;
114127 auto thread = env.startup ();
115128 thread.join ();
116129
0 commit comments