88
99#include " react/Domain.h"
1010#include " react/Signal.h"
11+ #include " react/Event.h"
12+ #include " react/Algorithm.h"
1113
1214using namespace std ;
1315using namespace react ;
1416
1517// Defines a domain.
1618// Each domain represents a separate dependency graph, managed by a dedicated propagation engine.
1719// Reactives of different domains can not be combined.
18- REACTIVE_DOMAIN (D)
20+ REACTIVE_DOMAIN (D, ToposortEngine<sequential_concurrent> )
1921
2022void SignalExample3 ()
2123{
@@ -27,7 +29,7 @@ void SignalExample3()
2729 // Inputs are implicitly thread-safe, buffered and executed in a continuation turn.
2830 // This continuation turn is queued just like a regular turn.
2931 // If other turns are already queued, they are executed before the continuation.
30- Observe (src, [&] (int v) {
32+ auto cont = MakeContinuation (src, [&] (int v) {
3133 cout << " V: " << v << endl;
3234 if (v < 10 )
3335 src <<= v+1 ;
@@ -38,9 +40,71 @@ void SignalExample3()
3840 cout << endl;
3941}
4042
43+ void SignalExample4 ()
44+ {
45+ REACTIVE_DOMAIN (L, ToposortEngine<sequential_concurrent>)
46+ REACTIVE_DOMAIN (R, ToposortEngine<sequential_concurrent>)
47+
48+ cout << " Signal Example 4" << endl;
49+
50+ auto srcL = MakeVar<L>(0 );
51+ auto srcR = MakeVar<R>(0 );
52+
53+ auto contL = MakeContinuation<L,R>(srcL, [&] (int v) {
54+ cout << " L->R: " << v << endl;
55+ if (v < 10 )
56+ srcR <<= v+1 ;
57+ });
58+
59+ auto contR = MakeContinuation<R,L>(srcR, [&] (int v) {
60+ cout << " R->L: " << v << endl;
61+ if (v < 10 )
62+ srcL <<= v+1 ;
63+ });
64+
65+ srcL <<= 1 ;
66+
67+ cout << endl;
68+ }
69+
70+ void SignalExample5 ()
71+ {
72+ REACTIVE_DOMAIN (L, ToposortEngine<sequential_concurrent>)
73+ REACTIVE_DOMAIN (R, ToposortEngine<sequential_concurrent>)
74+
75+ cout << " Signal Example 5" << endl;
76+
77+ auto srcL = MakeVar<L>(0 );
78+ auto depL1 = MakeVar<L>(0 );
79+ auto depL2 = MakeVar<L>(0 );
80+ auto srcR = MakeVar<R>(0 );
81+
82+ auto contL = MakeContinuation<L,R>(
83+ Monitor (srcL),
84+ With (depL1, depL2),
85+ [&] (int v, int depL1, int depL2) {
86+ cout << " L->R: " << v << endl;
87+ if (v < 10 )
88+ srcR <<= v+1 ;
89+ });
90+
91+ auto contR = MakeContinuation<R,L>(
92+ Monitor (srcR),
93+ [&] (int v) {
94+ cout << " R->L: " << v << endl;
95+ if (v < 10 )
96+ srcL <<= v+1 ;
97+ });
98+
99+ srcL <<= 1 ;
100+
101+ cout << endl;
102+ }
103+
41104int main ()
42105{
43106 SignalExample3 ();
107+ SignalExample4 ();
44108
45109#ifdef REACT_ENABLE_LOGGING
46110 std::ofstream logfile;
0 commit comments