Skip to content

Commit 135df9e

Browse files
committed
nodepp V1.4.0_5
1 parent 5876f03 commit 135df9e

83 files changed

Lines changed: 1926 additions & 1002 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
image.jpg
22
main.exe
33
build
4-
main
4+
main
5+
www
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include <nodepp/nodepp.h>
2+
#include <nodepp/worker.h>
3+
#include <nodepp/channel.h>
4+
#include <nodepp/encoder.h>
5+
6+
using namespace nodepp;
7+
8+
#include "module1.h"
9+
#include "module2.h"
10+
11+
void onMain(){
12+
13+
pair_t<worker_t,channel_t<coroutine_t>> module2 = module_2_start();
14+
pair_t<worker_t,channel_t<coroutine_t>> module1 = module_1_start();
15+
16+
module2.second.write( coroutine_t( COROUTINE(){
17+
coBegin
18+
19+
while( true ){
20+
console::log( "hello from module 2" );
21+
coDelay(100); }
22+
23+
coFinish
24+
}));
25+
26+
module1.second.write( coroutine_t( COROUTINE(){
27+
coBegin
28+
29+
while( true ){
30+
console::log( "hello from module 1" );
31+
coDelay(300); }
32+
33+
coFinish
34+
}));
35+
36+
process::add( coroutine::add( COROUTINE(){
37+
coBegin
38+
39+
while( true ){
40+
console::log( "<---------------->" );
41+
console::log( "<2>", module2.first.is_closed() );
42+
console::log( "<2>", module1.first.is_closed() );
43+
coDelay(1000); }
44+
45+
coFinish
46+
}));
47+
48+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <nodepp/nodepp.h>
2+
#include <nodepp/worker.h>
3+
#include <nodepp/channel.h>
4+
5+
using namespace nodepp;
6+
7+
pair_t<worker_t,channel_t<coroutine_t>> module_1_start();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef MODULE_1
2+
#define MODULE_1
3+
4+
pair_t<worker_t,channel_t<coroutine_t>> module_1_start(){
5+
6+
channel_t<coroutine_t> chn;
7+
8+
return { worker::add( coroutine::add( COROUTINE(){
9+
coBegin
10+
11+
while( true ){
12+
if ( !chn.empty() ){
13+
for ( auto &x: chn.read() ){ process::add( x ); }}
14+
if ( process::size() == 0 ){ coDelay(1000); } process::next(); }
15+
16+
coFinish
17+
}) ), chn };
18+
19+
}
20+
21+
#endif
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <nodepp/nodepp.h>
2+
#include <nodepp/worker.h>
3+
#include <nodepp/channel.h>
4+
5+
using namespace nodepp;
6+
7+
pair_t<worker_t,channel_t<coroutine_t>> module_2_start();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef MODULE_2
2+
#define MODULE_2
3+
4+
pair_t<worker_t,channel_t<coroutine_t>> module_2_start(){
5+
6+
channel_t<coroutine_t> chn;
7+
8+
return { worker::add( coroutine::add( COROUTINE(){
9+
coBegin
10+
11+
while( true ){
12+
if ( !chn.empty() ){
13+
for ( auto &x: chn.read() ){ process::add( x ); }}
14+
if ( process::size() == 0 ){ coDelay(1000); } process::next(); }
15+
16+
coFinish
17+
}) ), chn };
18+
19+
}
20+
21+
#endif

examples/0-stl_interop.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <nodepp/nodepp.h>
2+
#include <nodepp/event.h>
3+
4+
#include <string>
5+
#include <queue>
6+
#include <vector>
7+
#include <functional>
8+
9+
using namespace nodepp;
10+
11+
void onMain(){
12+
13+
ptr_t<int> ptr ( 0UL, 10 ); // as value
14+
// ptr_t<int> ptr ( 1UL, 10 ); // as buffer
15+
16+
std::function<void(int)> clb ([=]( int value ){
17+
console::log( value, *ptr );
18+
});
19+
20+
event_t<int> ev; ev.once( clb );
21+
ev.emit( 100 );
22+
23+
std::string str = "hello world";
24+
console::log( ">>", str );
25+
26+
std::vector<int> arr ({ 10, 20, 30, 40, 50 });
27+
console::log( ">>", array_t<int>( arr ).join() );
28+
29+
std::queue<int> st ({ 10, 20, 30, 40 });
30+
queue_t<int> que ( st );
31+
que.map([=]( int value ){ console::log( "<>", value ); });
32+
33+
}

examples/15-TCP.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <nodepp/nodepp.h>
2+
#include <nodepp/worker.h>
23
#include <nodepp/tcp.h>
34
#include <nodepp/fs.h>
45

@@ -74,9 +75,12 @@ void client(){
7475

7576
void onMain() {
7677

77-
if( process::env::get("mode")=="client" )
78-
{ client(); } else { server(); }
78+
worker::add( coroutine::add( COROUTINE(){
79+
coBegin /*--*/ ; server();
80+
process::wait(); coFinish }));
7981

80-
}
82+
worker::add( coroutine::add( COROUTINE(){
83+
coBegin /*--*/ ; client();
84+
process::wait(); coFinish }));
8185

82-
// g++ -o main main.cpp -I./include ; ./main ?mode=client
86+
}

examples/15-TLS.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <nodepp/nodepp.h>
2+
#include <nodepp/worker.h>
23
#include <nodepp/tls.h>
34
#include <nodepp/fs.h>
45

@@ -76,9 +77,12 @@ void client(){
7677

7778
void onMain() {
7879

79-
if( process::env::get("mode")=="client" )
80-
{ client(); } else { server(); }
80+
worker::add( coroutine::add( COROUTINE(){
81+
coBegin /*--*/ ; server();
82+
process::wait(); coFinish }));
8183

82-
}
84+
worker::add( coroutine::add( COROUTINE(){
85+
coBegin /*--*/ ; client();
86+
process::wait(); coFinish }));
8387

84-
// g++ -o main main.cpp -I./include ; ./main ?mode=client
88+
}

examples/15-UDP.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <nodepp/nodepp.h>
2+
#include <nodepp/worker.h>
23
#include <nodepp/udp.h>
34
#include <nodepp/fs.h>
45

@@ -77,9 +78,12 @@ void client(){
7778

7879
void onMain() {
7980

80-
if( process::env::get("mode")=="client" )
81-
{ client(); } else { server(); }
81+
worker::add( coroutine::add( COROUTINE(){
82+
coBegin /*--*/ ; server();
83+
process::wait(); coFinish }));
8284

83-
}
85+
worker::add( coroutine::add( COROUTINE(){
86+
coBegin /*--*/ ; client();
87+
process::wait(); coFinish }));
8488

85-
// g++ -o main main.cpp -I./include ; ./main ?mode=client
89+
}

0 commit comments

Comments
 (0)