|
|
@ -4,6 +4,7 @@ |
|
|
|
#include "../lib/trigger.hpp" |
|
|
|
#include "../lib/trigger.hpp" |
|
|
|
#include "../lib/filesystem.hpp" |
|
|
|
#include "../lib/filesystem.hpp" |
|
|
|
#include "../lib/timers.hpp" |
|
|
|
#include "../lib/timers.hpp" |
|
|
|
|
|
|
|
#include "../lib/define.hpp" |
|
|
|
|
|
|
|
|
|
|
|
using namespace marcelb::asynco; |
|
|
|
using namespace marcelb::asynco; |
|
|
|
using namespace triggers; |
|
|
|
using namespace triggers; |
|
|
@ -11,11 +12,13 @@ using namespace triggers; |
|
|
|
#include <iostream> |
|
|
|
#include <iostream> |
|
|
|
#include <unistd.h> |
|
|
|
#include <unistd.h> |
|
|
|
#include <thread> |
|
|
|
#include <thread> |
|
|
|
|
|
|
|
#include <future> |
|
|
|
|
|
|
|
|
|
|
|
using namespace std; |
|
|
|
using namespace std; |
|
|
|
using namespace this_thread; |
|
|
|
using namespace this_thread; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void sleep_to (int _time) { |
|
|
|
void sleep_to (int _time) { |
|
|
|
promise<void> _promise; |
|
|
|
promise<void> _promise; |
|
|
|
delayed t( [&]() { |
|
|
|
delayed t( [&]() { |
|
|
@ -131,31 +134,35 @@ int main () { |
|
|
|
// * Run an function asyncronic
|
|
|
|
// * Run an function asyncronic
|
|
|
|
// */
|
|
|
|
// */
|
|
|
|
|
|
|
|
|
|
|
|
// atask( []() {
|
|
|
|
nonsync ( []() { |
|
|
|
// sleep_for(2s); // only for simulate log duration function
|
|
|
|
sleep_for(2s); // only for simulate log duration function
|
|
|
|
// cout << "atask 1" << endl;
|
|
|
|
cout << "asynco 1" << endl; |
|
|
|
// return 5;
|
|
|
|
return 5; |
|
|
|
// });
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// /**
|
|
|
|
/**
|
|
|
|
// * Call not lambda function
|
|
|
|
* Call not lambda function |
|
|
|
// */
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nonsync (notLambdaFunction); |
|
|
|
|
|
|
|
|
|
|
|
// atask (notLambdaFunction);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wait ( |
|
|
|
|
|
|
|
nonsync ( |
|
|
|
|
|
|
|
notLambdaFunction |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// wait (
|
|
|
|
// async(launch::async, [] () {
|
|
|
|
// atask (
|
|
|
|
// cout << "Another thread in async style!" << endl;
|
|
|
|
// notLambdaFunction
|
|
|
|
// });
|
|
|
|
// )
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// /**
|
|
|
|
// /**
|
|
|
|
// * Call class method
|
|
|
|
// * Call class method
|
|
|
|
// */
|
|
|
|
// */
|
|
|
|
|
|
|
|
|
|
|
|
// clm classes;
|
|
|
|
// clm classes;
|
|
|
|
// atask( [&classes] () {
|
|
|
|
// asynco( [&classes] () {
|
|
|
|
// classes.classMethode();
|
|
|
|
// classes.classMethode();
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
@ -165,20 +172,20 @@ int main () { |
|
|
|
// * Wait after runned as async
|
|
|
|
// * Wait after runned as async
|
|
|
|
// */
|
|
|
|
// */
|
|
|
|
|
|
|
|
|
|
|
|
// auto a = atask( []() {
|
|
|
|
// auto a = asynco( []() {
|
|
|
|
// sleep_for(2s); // only for simulate log duration function
|
|
|
|
// sleep_for(2s); // only for simulate log duration function
|
|
|
|
// cout << "atask 2" << endl;
|
|
|
|
// cout << "asynco 2" << endl;
|
|
|
|
// return 5;
|
|
|
|
// return 5;
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
// cout << wait(a) << endl;
|
|
|
|
// cout << wait(a) << endl;
|
|
|
|
// cout << "print after atask 2" << endl;
|
|
|
|
// cout << "print after asynco 2" << endl;
|
|
|
|
|
|
|
|
|
|
|
|
// /**
|
|
|
|
// /**
|
|
|
|
// * Wait async function call and use i cout
|
|
|
|
// * Wait async function call and use i cout
|
|
|
|
// */
|
|
|
|
// */
|
|
|
|
|
|
|
|
|
|
|
|
// cout << wait(atask( [] () {
|
|
|
|
// cout << wait(asynco( [] () {
|
|
|
|
// sleep_for(chrono::seconds(1)); // only for simulate log duration function
|
|
|
|
// sleep_for(chrono::seconds(1)); // only for simulate log duration function
|
|
|
|
// cout << "wait end" << endl;
|
|
|
|
// cout << "wait end" << endl;
|
|
|
|
// return 4;
|
|
|
|
// return 4;
|
|
|
@ -209,9 +216,9 @@ int main () { |
|
|
|
// */
|
|
|
|
// */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// atask( [] {
|
|
|
|
// asynco( [] {
|
|
|
|
// cout << "idemo ..." << endl;
|
|
|
|
// cout << "idemo ..." << endl;
|
|
|
|
// atask( [] {
|
|
|
|
// asynco( [] {
|
|
|
|
// cout << "ugdnježdena async funkcija " << endl;
|
|
|
|
// cout << "ugdnježdena async funkcija " << endl;
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
// });
|
|
|
@ -222,68 +229,68 @@ int main () { |
|
|
|
* initialization of typed events |
|
|
|
* initialization of typed events |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
trigger<int, int> ev2int; |
|
|
|
// trigger<int, int> ev2int;
|
|
|
|
trigger<int, string> evintString; |
|
|
|
// trigger<int, string> evintString;
|
|
|
|
trigger<> evoid; |
|
|
|
// trigger<> evoid;
|
|
|
|
|
|
|
|
|
|
|
|
ev2int.on("sum", [](int a, int b) { |
|
|
|
// ev2int.on("sum", [](int a, int b) {
|
|
|
|
cout << "Sum " << a+b << endl; |
|
|
|
// cout << "Sum " << a+b << endl;
|
|
|
|
}); |
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
ev2int.on("sum", [](int a, int b) { |
|
|
|
// ev2int.on("sum", [](int a, int b) {
|
|
|
|
cout << "Sum done" << endl; |
|
|
|
// cout << "Sum done" << endl;
|
|
|
|
}); |
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
evintString.on("substract", [](int a, string b) { |
|
|
|
// evintString.on("substract", [](int a, string b) {
|
|
|
|
cout << "Substract " << a-stoi(b) << endl; |
|
|
|
// cout << "Substract " << a-stoi(b) << endl;
|
|
|
|
}); |
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
evoid.on("void", []() { |
|
|
|
// evoid.on("void", []() {
|
|
|
|
cout << "Void emited" << endl; |
|
|
|
// cout << "Void emited" << endl;
|
|
|
|
}); |
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
string emited2 = "2"; |
|
|
|
// string emited2 = "2";
|
|
|
|
|
|
|
|
|
|
|
|
evoid.on("void", [&]() { |
|
|
|
// evoid.on("void", [&]() {
|
|
|
|
cout << "Void emited " << emited2 << endl; |
|
|
|
// cout << "Void emited " << emited2 << endl;
|
|
|
|
}); |
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
evoid.tick("void"); |
|
|
|
// evoid.tick("void");
|
|
|
|
sleep(1); |
|
|
|
// sleep(1);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
// /**
|
|
|
|
* Emit |
|
|
|
// * Emit
|
|
|
|
*/ |
|
|
|
// */
|
|
|
|
|
|
|
|
|
|
|
|
ev2int.tick("sum", 5, 8); |
|
|
|
// ev2int.tick("sum", 5, 8);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sleep(1); |
|
|
|
// sleep(1);
|
|
|
|
evintString.tick("substract", 3, to_string(2)); |
|
|
|
// evintString.tick("substract", 3, to_string(2));
|
|
|
|
|
|
|
|
|
|
|
|
sleep(1); |
|
|
|
// sleep(1);
|
|
|
|
evoid.off("void"); |
|
|
|
// evoid.off("void");
|
|
|
|
evoid.tick("void"); |
|
|
|
// evoid.tick("void");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cout << "Ukupno 2 int " << ev2int.listeners() << endl; |
|
|
|
// cout << "Ukupno 2 int " << ev2int.listeners() << endl;
|
|
|
|
cout << "Ukupno evintString " << evintString.listeners() << endl; |
|
|
|
// cout << "Ukupno evintString " << evintString.listeners() << endl;
|
|
|
|
cout << "Ukupno evoid " << evoid.listeners() << endl; |
|
|
|
// cout << "Ukupno evoid " << evoid.listeners() << endl;
|
|
|
|
cout << "Ukupno 2 int " << ev2int.listeners("sum") << endl; |
|
|
|
// cout << "Ukupno 2 int " << ev2int.listeners("sum") << endl;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
// /**
|
|
|
|
* Own class
|
|
|
|
// * Own class
|
|
|
|
*/ |
|
|
|
// */
|
|
|
|
|
|
|
|
|
|
|
|
myOwnClass myclass; |
|
|
|
// myOwnClass myclass;
|
|
|
|
|
|
|
|
|
|
|
|
delayed t( [&] { |
|
|
|
// delayed t( [&] {
|
|
|
|
myclass.tick("constructed", 1); |
|
|
|
// myclass.tick("constructed", 1);
|
|
|
|
}, 200); |
|
|
|
// }, 200);
|
|
|
|
|
|
|
|
|
|
|
|
myclass.on("constructed", [] (int i) { |
|
|
|
// myclass.on("constructed", [] (int i) {
|
|
|
|
cout << "Constructed " << i << endl; |
|
|
|
// cout << "Constructed " << i << endl;
|
|
|
|
}); |
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|