C++ library for asynchronous and event-driven execution
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
asynco/test/test.cpp

105 lines
2.6 KiB

#include "../lib/loop.hpp"
#include "../lib/asynco.hpp"
// #include "../lib/event.hpp"
#include <iostream>
#include <unistd.h>
using namespace std;
using namespace marcelb;
using namespace this_thread;
#ifndef ON_ASYNC
#define ON_ASYNC
AsyncLoop on_async;
#endif
int main () {
auto start = chrono::high_resolution_clock::now();
interval inter1 ([&]() {
cout << "interval prvi " << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << endl;
}, 1000);
cout << "Blokira stoka" << endl;
interval inter2 ([&]() {
cout << "interval drugi " << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << endl;
}, 2000);
interval inter3 ([&]() {
cout << "interval treći " << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << endl;
}, 3000);
timeout time1 ( [&] () {
cout << "Close interval 1 i 2 " << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << endl;
inter1.clear();
inter2.clear();
}, 10000);
timeout time2 ([&] () {
cout << "Close interval 3 " << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << endl;
inter3.clear();
}, 20000);
// for (int i = 0; i < 8; ++i) {
// pool.put_task( [&] (int id) {
// this_thread::sleep_for(chrono::seconds(1));
// cout << a*i << endl;
// }, i);
// }
// auto res1 = pool.put_task( [] () {
// cout << "Jebiga " <<endl;
// throw string ("jebiga!!");
// });
// try {
// res1.get();
// } catch (const string except) {
// cout << except << endl;
// }
// auto res = pool.put_task( []() {
// this_thread::sleep_for(chrono::seconds(1));
// return 4;
// });
// cout << wait(asynco( [] () {
// sleep_for(chrono::seconds(1));
// cout << "RETURN" << endl;
// return 4;
// })) << endl;
// asynco( []() {
// sleep_for(2s);
// cout << "RETURN 2" << endl;
// return 5;
// });
// cout << wait(pool.put_task( []() {
// this_thread::sleep_for(chrono::seconds(1));
// return 7;
// }));
// cout << wait(run1) << endl;
// event dog;
// dog.on("roge", [](int a, int b) {
// cout << "Rogeee" << a << b << endl;
// });
// sleep(5);
// dog.emit("roge", 5, 8);
sleep(1000);
return 0;
}