-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathmain.cpp
More file actions
47 lines (31 loc) · 915 Bytes
/
Copy pathmain.cpp
File metadata and controls
47 lines (31 loc) · 915 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <nodepp/nodepp.h>
#include <nodepp/worker.h>
#include <nodepp/channel.h>
using namespace nodepp;
channel_t<coroutine_t> ch1, ch2;
int worker_1(){
coStart
while( true ){ coDelay(1000);
ch2.write( coroutine_t( COROUTINE(){
console::log( "worker1 -> worker2", process::now() );
return -1; }) );
for( auto x: ch1.read() ){ process::add( x ); }}
coStop
}
int worker_2(){
coStart
while( true ){ coDelay(1000);
ch1.write( coroutine_t( COROUTINE(){
console::log( "worker2 -> worker1", process::now() );
return -1; }) );
for( auto x: ch2.read() ){ process::add( x ); }}
coStop
}
void onMain(){
worker ::add([=](){
process::add([=](){ return worker_1(); });
process::wait(); return -1; });
worker ::add([=](){
process::add([=](){ return worker_2(); });
process::wait(); return -1; });
}