@ -1,12 +1,12 @@
// #define NUM_OF_RUNNERS 2
// // #define NUM_OF_RUNNERS 2
# include "../lib/asynco.hpp"
# include "../lib/even t.hpp"
# include "../lib/trigger .hpp"
# include "../lib/filesystem.hpp"
# include "../lib/timers.hpp"
using namespace marcelb : : asynco ;
using namespace even ts;
using namespace trigger s ;
# include <iostream>
# include <unistd.h>
@ -18,7 +18,7 @@ using namespace this_thread;
void sleep_to ( int _time ) {
promise < void > _promise ;
timeout t ( [ & ] ( ) {
delayed t ( [ & ] ( ) {
_promise . set_value ( ) ;
} , _time ) ;
@ -27,7 +27,7 @@ void sleep_to (int _time) {
void promise_reject ( int _time ) {
promise < void > _promise ;
timeout t ( [ & ] ( ) {
delayed t ( [ & ] ( ) {
try {
// simulate except
throw runtime_error ( " Error simulation " ) ;
@ -53,9 +53,9 @@ class clm {
// ------------------ EXTEND OWN CLASS WITH EVENTS -------------------
class myOwnClass : public even t< int > {
class myOwnClass : public trigger < int > {
public :
myOwnClass ( ) : even t( ) { } ;
myOwnClass ( ) : trigger ( ) { } ;
} ;
@ -66,36 +66,36 @@ int main () {
// --------------- TIME ASYNCHRONOUS FUNCTIONS --------------
// /**
// * Init interval and timeout; clear interval and timeout
// * Init periodic and delayed; clear periodic and delayed
// */
// interval inter1 ([&]() {
// cout << "interval prvi " << rtime_ms() - start << endl;
// periodic inter1 ([&]() {
// cout << "periodic prvi " << rtime_ms() - start << endl;
// }, 1000);
// interval inter2 ([&]() {
// cout << "interval drugi " << rtime_ms() - start << endl;
// periodic inter2 ([&]() {
// cout << "periodic drugi " << rtime_ms() - start << endl;
// }, 2000);
// interval inter3 ([&]() {
// cout << "interval treći " << rtime_ms() - start << endl;
// periodic inter3 ([&]() {
// cout << "periodic treći " << rtime_ms() - start << endl;
// }, 1000);
// interval inter4 ([&]() {
// // cout << "interval cetvrti " << rtime_ms() - start << endl;
// periodic inter4 ([&]() {
// // cout << "periodic cetvrti " << rtime_ms() - start << endl;
// cout << "Ticks " << inter3.ticks() << endl;
// }, 500);
// interval inter5 ([&]() {
// cout << "interval peti " << rtime_ms() - start << endl;
// periodic inter5 ([&]() {
// cout << "periodic peti " << rtime_ms() - start << endl;
// }, 2000);
// interval inter6 ([&]() {
// cout << "interval sesti " << rtime_ms() - start << endl;
// periodic inter6 ([&]() {
// cout << "periodic sesti " << rtime_ms() - start << endl;
// }, 3000);
// timeout time1 ( [&] () {
// cout << "Close interval 1 i 2 " << rtime_ms() - start << endl;
// delayed time1 ( [&] () {
// cout << "Close periodic 1 i 2 " << rtime_ms() - start << endl;
// inter1.stop();
// cout << "inter1.stop " << endl;
// inter2.stop();
@ -103,8 +103,8 @@ int main () {
// }, 8000);
// timeout time2 ([&] () {
// cout << "Close interval 3 " << rtime_ms() - start << endl;
// delayed time2 ([&] () {
// cout << "Close periodic 3 " << rtime_ms() - start << endl;
// inter3.stop();
// cout << "Stoped " << inter3.stoped() << endl;
// // time1.stop();
@ -185,7 +185,7 @@ int main () {
// })) << endl;
// /**
// * Sleep with timeout sleep implement
// * Sleep with delayed sleep implement
// */
// sleep_to(3000);
@ -216,68 +216,74 @@ int main () {
// });
// });
// // // --------------- EVENTS -------------------
// --------------- EVENTS -------------------
// /**
// * initialization of typed events
// */
/**
* initialization of typed events
*/
// event<int, int> ev2int;
// event<int, string> evintString;
// event<> evoid;
trigger < int , int > ev2int ;
trigger < int , string > evintString ;
trigger < > evoid ;
// ev2int.on("sum", [](int a, int b) {
// cout << "Sum " << a+b << endl;
// });
ev2int . on ( " sum " , [ ] ( int a , int b ) {
cout < < " Sum " < < a + b < < endl ;
} ) ;
// ev2int.on("sum", [](int a, int b) {
// cout << "Sum done" << endl;
// });
ev2int . on ( " sum " , [ ] ( int a , int b ) {
cout < < " Sum done " < < endl ;
} ) ;
// evintString.on("substract", [](int a, string b) {
// cout << "Substract " << a-stoi(b) << endl;
// });
evintString . on ( " substract " , [ ] ( int a , string b ) {
cout < < " Substract " < < a - stoi ( b ) < < endl ;
} ) ;
// evoid.on("void", []() {
// cout << "Void emited" << endl;
// });
evoid . on ( " void " , [ ] ( ) {
cout < < " Void emited " < < endl ;
} ) ;
// string emited2 = "2";
string emited2 = " 2 " ;
// evoid.on("void", [&]() {
// cout << "Void emited " << emited2 << endl;
// });
evoid . on ( " void " , [ & ] ( ) {
cout < < " Void emited " < < emited2 < < endl ;
} ) ;
// evoid.emit("void");
// sleep(1);
evoid . tick ( " void " ) ;
sleep ( 1 ) ;
// /**
// * Emit
// */
/**
* Emit
*/
// ev2int.emit("sum", 5, 8);
ev2int . tick ( " sum " , 5 , 8 ) ;
// sleep(1);
// evintString.emit("substract", 3, to_string(2));
sleep ( 1 ) ;
evintString . tick ( " substract " , 3 , to_string ( 2 ) ) ;
// sleep(1);
// evoid.off("void");
// evoid.emit("void");
sleep ( 1 ) ;
evoid . off ( " void " ) ;
evoid . tick ( " void " ) ;
// /**
// * Own class
// */
// myOwnClass myclass;
cout < < " Ukupno 2 int " < < ev2int . listeners ( ) < < endl ;
cout < < " Ukupno evintString " < < evintString . listeners ( ) < < endl ;
cout < < " Ukupno evoid " < < evoid . listeners ( ) < < endl ;
cout < < " Ukupno 2 int " < < ev2int . listeners ( " sum " ) < < endl ;
// timeout t( [&] {
// myclass.emit("constructed", 1);
// }, 200);
/**
* Own class
*/
// myclass.on("constructed", [] (int i) {
// cout << "Constructed " << i << endl;
// });
myOwnClass myclass ;
delayed t ( [ & ] {
myclass . tick ( " constructed " , 1 ) ;
} , 200 ) ;
myclass . on ( " constructed " , [ ] ( int i ) {
cout < < " Constructed " < < i < < endl ;
} ) ;
@ -307,7 +313,7 @@ int main () {
// });
// ----------------------------------------------------------------------------------------------------
// // ----------------------------------------------------------------------------------------------------
cout < < " Run " < < endl ;
_asynco_engine . run ( ) ;