Rename definition for awaitable coruotines
This commit is contained in:
parent
aca2724e0c
commit
9965f1e1c7
@ -421,11 +421,11 @@ try {
|
|||||||
|
|
||||||
## Coroutine
|
## Coroutine
|
||||||
|
|
||||||
If `define.hpp` is included, you can initialize coroutines using `coroutine<T>`; if not, just use `boost::asio::awaitable<T>`.
|
If `define.hpp` is included, you can initialize coroutines using `asyncable<T>`; if not, just use `boost::asio::awaitable<T>`.
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
|
|
||||||
coroutine<int> c2(int a) {
|
asyncable<int> c2(int a) {
|
||||||
co_return a * 2;
|
co_return a * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -440,7 +440,7 @@ Or using a lambda expression:
|
|||||||
|
|
||||||
```c++
|
```c++
|
||||||
|
|
||||||
async_([]() -> coroutine<void> {
|
async_([]() -> asyncable<void> {
|
||||||
std::cout << "Hello" << std::endl;
|
std::cout << "Hello" << std::endl;
|
||||||
co_await c2(4);
|
co_await c2(4);
|
||||||
co_return;
|
co_return;
|
||||||
|
@ -12,7 +12,7 @@ namespace asynco {
|
|||||||
#define await_ marcelb::asynco::await_
|
#define await_ marcelb::asynco::await_
|
||||||
|
|
||||||
#if __cplusplus >= 202002L
|
#if __cplusplus >= 202002L
|
||||||
#define coroutine boost::asio::awaitable
|
#define asyncable boost::asio::awaitable
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,13 @@ using namespace marcelb::asynco;
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace this_thread;
|
using namespace this_thread;
|
||||||
|
|
||||||
coroutine<int> c2 (int a) {
|
asyncable<int> c2 (int a) {
|
||||||
co_return a*2;
|
co_return a*2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
coroutine<void> c () {
|
asyncable<void> c () {
|
||||||
cout << "Ispisi" << endl;
|
cout << "Ispisi" << endl;
|
||||||
co_await c2(0);
|
co_await c2(0);
|
||||||
co_return;
|
co_return;
|
||||||
@ -458,7 +458,7 @@ int main () {
|
|||||||
// // ----------------------------------------------------------------------------------------------------
|
// // ----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
// auto i = async_ ( []() -> coroutine<int> {
|
// auto i = async_ ( []() -> asyncable<int> {
|
||||||
// cout << "aaaa" << endl;
|
// cout << "aaaa" << endl;
|
||||||
// co_return 5;
|
// co_return 5;
|
||||||
// });
|
// });
|
||||||
@ -470,7 +470,7 @@ int main () {
|
|||||||
// cout << i_ << endl;
|
// cout << i_ << endl;
|
||||||
|
|
||||||
|
|
||||||
// Periodic a( []() -> coroutine<void> {
|
// Periodic a( []() -> asyncable<void> {
|
||||||
// cout << "corutina" << endl;
|
// cout << "corutina" << endl;
|
||||||
// // co_await retint();
|
// // co_await retint();
|
||||||
// }, 2000);
|
// }, 2000);
|
||||||
@ -485,15 +485,15 @@ int main () {
|
|||||||
// Trigger<int, string> evintString;
|
// Trigger<int, string> evintString;
|
||||||
Trigger<> evoid;
|
Trigger<> evoid;
|
||||||
|
|
||||||
// ev2int.on("sum", [](int a, int b) -> coroutine<void> {
|
// ev2int.on("sum", [](int a, int b) -> asyncable<void> {
|
||||||
// cout << "Sum " << a+b << endl;
|
// cout << "Sum " << a+b << endl;
|
||||||
// });
|
// });
|
||||||
|
|
||||||
// ev2int.on("sum", [](int a, int b) -> coroutine<void> {
|
// ev2int.on("sum", [](int a, int b) -> asyncable<void> {
|
||||||
// cout << "Sum done" << endl;
|
// cout << "Sum done" << endl;
|
||||||
// });
|
// });
|
||||||
|
|
||||||
// evintString.on("substract", [](int a, string b) -> coroutine<void> {
|
// evintString.on("substract", [](int a, string b) -> asyncable<void> {
|
||||||
// cout << "Substract " << a-stoi(b) << endl;
|
// cout << "Substract " << a-stoi(b) << endl;
|
||||||
// });
|
// });
|
||||||
|
|
||||||
@ -503,33 +503,35 @@ int main () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// auto c1 = []() -> coroutine<void> {
|
// auto c1 = []() -> asyncable<void> {
|
||||||
// cout << "Roge " << endl;
|
// cout << "Roge " << endl;
|
||||||
// co_return;
|
// co_return;
|
||||||
|
|
||||||
// };
|
// };
|
||||||
|
|
||||||
// async_ ( c2(3));
|
async_ ( c2(3));
|
||||||
|
|
||||||
async_ ([]() -> coroutine<void> {
|
|
||||||
|
async_ ([]() -> asyncable<void> {
|
||||||
cout << "Hello" << endl;
|
cout << "Hello" << endl;
|
||||||
co_await c2(4);
|
co_await c2(4);
|
||||||
co_return;
|
co_return;
|
||||||
}());
|
}());
|
||||||
|
|
||||||
Periodic p( []() {
|
// Periodic p( []() {
|
||||||
auto a = await_ (async_ (c2(34)));
|
// async_ (
|
||||||
cout << "A " << a << endl;
|
// c2(34)
|
||||||
}, 2000);
|
// );
|
||||||
|
// }, 2000);
|
||||||
|
|
||||||
// await_( async_co2 ( [c1 = move(c1)]() -> coroutine<void> {
|
// await_( async_co2 ( [c1 = move(c1)]() -> asyncable<void> {
|
||||||
// cout << "Baba roga" << endl;
|
// cout << "Baba roga" << endl;
|
||||||
// co_await c1();
|
// co_await c1();
|
||||||
// }));
|
// }));
|
||||||
|
|
||||||
// string emited2 = "2";
|
// string emited2 = "2";
|
||||||
|
|
||||||
// evoid.on("void", [&]() -> coroutine<void> {
|
// evoid.on("void", [&]() -> asyncable<void> {
|
||||||
// cout << "Void emited " << emited2 << endl;
|
// cout << "Void emited " << emited2 << endl;
|
||||||
// });
|
// });
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user