#ifndef _ASYNCO_DEFAULT_ #define _ASYNCO_DEFAULT_ #include "asynco.hpp" namespace marcelb { namespace asynco { extern Asynco Asynco_Default_Runtime; /** * Run the function asynchronously */ template auto async_(F&& f, Args&&... args) -> future> { return Asynco_Default_Runtime.async(bind(forward(f), forward(args)...)); } #if __cplusplus >= 202002L /** * Run the coroutine */ template std::future async_(boost::asio::awaitable _coroutine) { return Asynco_Default_Runtime.async(move(_coroutine)); } #endif /** * Block until the asynchronous call completes - dont block asynco engine loop */ template T await_(future& r, uint16_t time_us = 10) { return Asynco_Default_Runtime.await(r, time_us); } /** * Block until the asynchronous call completes - dont block asynco engine loop */ template T await_(future&& r, uint16_t time_us = 10) { return Asynco_Default_Runtime.await(r, time_us); } /** * Run the function asynchronously an block until completes */ template auto await_(F&& f, Args&&... args) -> invoke_result_t { return Asynco_Default_Runtime.await(bind(forward(f), forward(args)...)); } #if __cplusplus >= 202002L /** * Run the coruotine and wait */ template T await_(boost::asio::awaitable _coroutine) { return Asynco_Default_Runtime.await(move(_coroutine)); } #endif /** * Block until the multiple asynchronous call completes * Use only on no-void calls */ template auto await_(F&&... f) -> std::tuple::type...> { return Asynco_Default_Runtime.await(move(f)...); } /** * Block until the multiple asynchronous call completes * Use only on no-void calls */ template auto await_(F&... f) -> std::tuple::type...> { return Asynco_Default_Runtime.await(f...);; } Timer delayed(function callback, uint64_t time); Timer periodic(function callback, uint64_t time); template Trigger trigger() { return Trigger(Asynco_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(); void asynco_default_run(); void asynco_default_run_on_this(); void asynco_default_join(); io_context& asynco_default_io_context(); } } #endif