Compare commits
No commits in common. "dev" and "refaktor" have entirely different histories.
@ -26,8 +26,6 @@ namespace asynco {
|
||||
|
||||
/**
|
||||
* Asynco runtime
|
||||
* Used for all asynchronous capabilities of this wrapper
|
||||
* Initializes threads and boost::asio::io_context
|
||||
*/
|
||||
class Asynco {
|
||||
vector<thread> _runners;
|
||||
@ -38,26 +36,14 @@ class Asynco {
|
||||
public:
|
||||
io_context io_ctx;
|
||||
|
||||
/**
|
||||
* It starts the thread initialization and the Boost::Asio event loop in each of them
|
||||
*/
|
||||
|
||||
void run(uint8_t threads = thread::hardware_concurrency());
|
||||
|
||||
/**
|
||||
* Starts Boost::Asio event loop in the current thread
|
||||
*/
|
||||
|
||||
void run_on_this();
|
||||
|
||||
/**
|
||||
* Waits until all threads have finished working
|
||||
*/
|
||||
|
||||
void join();
|
||||
|
||||
/**
|
||||
* Run the function asynchronously in runtime
|
||||
* Run the function asynchronously
|
||||
*/
|
||||
template<class F, class... Args>
|
||||
auto async(F&& f, Args&&... args) -> future<invoke_result_t<F, Args...>> {
|
||||
@ -68,7 +54,7 @@ public:
|
||||
|
||||
#if __cplusplus >= 202002L
|
||||
/**
|
||||
* Run the coroutine in runtime
|
||||
* Run the coroutine
|
||||
*/
|
||||
template <typename T>
|
||||
future<T> async(boost::asio::awaitable<T> _coroutine) {
|
||||
@ -94,7 +80,7 @@ public:
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Wait until the asynchronous call completes
|
||||
* Block until the asynchronous call completes - dont block asynco engine loop
|
||||
*/
|
||||
template<typename T>
|
||||
T await(future<T>& r, uint16_t time_us = 10) {
|
||||
@ -105,7 +91,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait until the asynchronous call completes
|
||||
* Block until the asynchronous call completes - dont block asynco engine loop
|
||||
*/
|
||||
template<typename T>
|
||||
T await(future<T>&& r, uint16_t time_us = 10) {
|
||||
@ -116,7 +102,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the function asynchronously an wait until completes
|
||||
* Run the function asynchronously an block until completes
|
||||
*/
|
||||
template<class F, class... Args>
|
||||
auto await(F&& f, Args&&... args) -> invoke_result_t<F, Args...> {
|
||||
@ -139,17 +125,17 @@ public:
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Wait until the multiple asynchronous call completes
|
||||
* Block until the multiple asynchronous call completes
|
||||
* Use only on no-void calls
|
||||
*/
|
||||
|
||||
template<typename... F>
|
||||
auto await(F&&... f) -> tuple<typename decay<decltype(await(f))>::type...> {
|
||||
return make_tuple(await(f)...);
|
||||
return make_tuple(move(f).get()...);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait until the multiple asynchronous call completes
|
||||
* Block until the multiple asynchronous call completes
|
||||
* Use only on no-void calls
|
||||
*/
|
||||
|
||||
@ -158,21 +144,13 @@ public:
|
||||
return make_tuple(await(f)...);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the delayed timer
|
||||
*/
|
||||
Timer delayed(function<void()> callback, uint64_t time) ;/*{
|
||||
return Timer(io_ctx, callback, time, TimerType::Delayed);
|
||||
}*/
|
||||
|
||||
Timer delayed(function<void()> callback, uint64_t time);
|
||||
|
||||
/**
|
||||
* Initialize the periodic timer
|
||||
*/
|
||||
|
||||
Timer periodic(function<void()> callback, uint64_t time);
|
||||
|
||||
/**
|
||||
* Initialize trigger (typed event)
|
||||
*/
|
||||
Timer periodic(function<void()> callback, uint64_t time) ;/*{
|
||||
return Timer(io_ctx, callback, time, TimerType::Periodic);
|
||||
}*/
|
||||
|
||||
template<typename... T>
|
||||
Trigger<T...> trigger() {
|
||||
|
@ -6,14 +6,11 @@
|
||||
namespace marcelb {
|
||||
namespace asynco {
|
||||
|
||||
/**
|
||||
* Default runtime
|
||||
*/
|
||||
|
||||
extern Asynco Asynco_Default_Runtime;
|
||||
|
||||
/**
|
||||
* Run the function asynchronously in default runtime
|
||||
* Run the function asynchronously
|
||||
*/
|
||||
template<class F, class... Args>
|
||||
auto async_(F&& f, Args&&... args) -> future<invoke_result_t<F, Args...>> {
|
||||
@ -22,7 +19,7 @@ auto async_(F&& f, Args&&... args) -> future<invoke_result_t<F, Args...>> {
|
||||
|
||||
#if __cplusplus >= 202002L
|
||||
/**
|
||||
* Run the coroutine in default runtime
|
||||
* Run the coroutine
|
||||
*/
|
||||
template <typename T>
|
||||
std::future<T> async_(boost::asio::awaitable<T> _coroutine) {
|
||||
@ -31,7 +28,7 @@ std::future<T> async_(boost::asio::awaitable<T> _coroutine) {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Wait until the asynchronous call completes
|
||||
* Block until the asynchronous call completes - dont block asynco engine loop
|
||||
*/
|
||||
template<typename T>
|
||||
T await_(future<T>& r, uint16_t time_us = 10) {
|
||||
@ -39,7 +36,7 @@ T await_(future<T>& r, uint16_t time_us = 10) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait until the asynchronous call completes
|
||||
* Block until the asynchronous call completes - dont block asynco engine loop
|
||||
*/
|
||||
template<typename T>
|
||||
T await_(future<T>&& r, uint16_t time_us = 10) {
|
||||
@ -47,7 +44,7 @@ T await_(future<T>&& r, uint16_t time_us = 10) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the function asynchronously an wait until completes
|
||||
* Run the function asynchronously an block until completes
|
||||
*/
|
||||
template<class F, class... Args>
|
||||
auto await_(F&& f, Args&&... args) -> invoke_result_t<F, Args...> {
|
||||
@ -66,7 +63,7 @@ T await_(boost::asio::awaitable<T> _coroutine) {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Wait until the multiple asynchronous call completes
|
||||
* Block until the multiple asynchronous call completes
|
||||
* Use only on no-void calls
|
||||
*/
|
||||
|
||||
@ -76,7 +73,7 @@ auto await_(F&&... f) -> std::tuple<typename std::decay<decltype(Asynco_Default_
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait until the multiple asynchronous call completes
|
||||
* Block until the multiple asynchronous call completes
|
||||
* Use only on no-void calls
|
||||
*/
|
||||
|
||||
@ -85,66 +82,31 @@ auto await_(F&... f) -> std::tuple<typename std::decay<decltype(Asynco_Default_R
|
||||
return Asynco_Default_Runtime.await(f...);;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the delayed timer
|
||||
*/
|
||||
|
||||
Timer delayed(function<void()> callback, uint64_t time);
|
||||
|
||||
/**
|
||||
* Initialize the periodic timer
|
||||
*/
|
||||
|
||||
Timer periodic(function<void()> callback, uint64_t time);
|
||||
|
||||
/**
|
||||
* Initialize trigger (typed event)
|
||||
*/
|
||||
|
||||
template<typename... T>
|
||||
Trigger<T...> trigger() {
|
||||
return Trigger<T...>(Asynco_Default_Runtime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get reference of default runtime
|
||||
* Alternative names of functions - mostly for the sake of more beautiful coloring of the code
|
||||
*/
|
||||
#define async_ marcelb::asynco::async_
|
||||
#define await_ marcelb::asynco::await_
|
||||
|
||||
Asynco& asynco_default_runtime();
|
||||
|
||||
/**
|
||||
* Run default runtime
|
||||
*/
|
||||
|
||||
void asynco_default_run();
|
||||
|
||||
/**
|
||||
* Run default runtime in this thread
|
||||
*/
|
||||
|
||||
void asynco_default_run_on_this();
|
||||
|
||||
/**
|
||||
* Waits until all threads have finished working
|
||||
*/
|
||||
|
||||
void asynco_default_join();
|
||||
|
||||
/**
|
||||
* Get reference of boost::asio::io_context
|
||||
*/
|
||||
|
||||
io_context& asynco_default_io_context();
|
||||
|
||||
/**
|
||||
* Run the function asynchronously in default runtime
|
||||
*/
|
||||
#define async_ marcelb::asynco::async_
|
||||
|
||||
/**
|
||||
* Wait until the asynchronous call completes
|
||||
*/
|
||||
#define await_ marcelb::asynco::await_
|
||||
|
||||
|
||||
}
|
||||
|
@ -77,7 +77,6 @@ class Timer {
|
||||
* The logic status of the timer stop state
|
||||
*/
|
||||
bool stoped();
|
||||
|
||||
/**
|
||||
* The destructor stops the timer
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user