#ifndef _ASYNCO_DEFAULT_ #define _ASYNCO_DEFAULT_ #include "asynco.hpp" namespace marcelb { namespace asynco { /** * Default runtime */ extern Asynco Asynco_Default_Runtime; /** * Run the function asynchronously in default runtime */ template auto async_(F&& f, Args&&... args) -> future> { return Asynco_Default_Runtime.async(bind(forward(f), forward(args)...)); } #if __cplusplus >= 202002L /** * Run the coroutine in default runtime */ template std::future async_(boost::asio::awaitable _coroutine) { return Asynco_Default_Runtime.async(move(_coroutine)); } #endif /** * Wait until the asynchronous call completes */ template T await_(future& r, uint16_t time_us = 10) { return Asynco_Default_Runtime.await(r, time_us); } /** * Wait until the asynchronous call completes */ template T await_(future&& r, uint16_t time_us = 10) { return Asynco_Default_Runtime.await(r, time_us); } /** * Run the function asynchronously an wait 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 /** * Wait 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)...); } /** * Wait 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...);; } /** * Initialize the delayed timer */ Timer delayed(function callback, uint64_t time); /** * Initialize the periodic timer */ Timer periodic(function callback, uint64_t time); /** * Initialize trigger (typed event) */ template Trigger trigger() { return Trigger(Asynco_Default_Runtime); } /** * Get reference of default runtime */ 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_ } } #endif