GKD.RoboCtrl
载入中...
搜索中...
未找到
roboctrl::async::task_context类 参考

异步任务上下文类。 更多...

详细描述

异步任务上下文类。

提供基于Asio的异步任务执行环境,支持协程任务的调度和执行。

在文件 async.hpp51 行定义.

#include <async.hpp>

类 roboctrl::async::task_context 继承关系图:
roboctrl::utils::singleton_base< task_context > roboctrl::log::logable< task_context > roboctrl::utils::immovable_base roboctrl::utils::not_copyable_base

struct  info_type
 

Public 类型

using task_type = awaitable<>
 

Public 成员函数

void spawn (task_type &&task)
 添加一个协程任务到上下文中执行。
 
template<typename Fn , typename... Args>
void post (Fn &&fn, Args &&... args)
 添加一个任务到上下文中执行。
 
void run ()
 开始运行任务上下文。
 
void stop ()
 
bool init (info_type _info)
 初始化 task_context
 
std::string desc () const
 task_context的描述
 
auto get_executor ()
 获取asio的executor。
 
auto asio_context () -> asio::io_context &
 获取asio的io_context。
 
- Public 成员函数 继承自 roboctrl::utils::singleton_base< task_context >
 singleton_base (const singleton_base &)=delete
 
singleton_baseoperator= (const singleton_base &)=delete
 
- Public 成员函数 继承自 roboctrl::utils::immovable_base
 immovable_base (immovable_base &&)=delete
 
immovable_baseoperator= (immovable_base &&)=delete
 
- Public 成员函数 继承自 roboctrl::utils::not_copyable_base
 not_copyable_base (const not_copyable_base &)=delete
 
not_copyable_baseoperator= (const not_copyable_base &)=delete
 

额外继承的成员函数

- 静态 Public 成员函数 继承自 roboctrl::utils::singleton_base< task_context >
static task_contextinstance ()
 获取单例实例
 
- Protected 成员函数 继承自 roboctrl::log::logable< task_context >
void log (log_level level, std::format_string< Args... > fmt, Args &&...args) const
 输出日志
 
void log_debug (std::format_string< Args... > fmt, Args &&...args) const
 输出debug日志
 
void log_info (std::format_string< Args... > fmt, Args &&...args) const
 输出info日志
 
void log_warn (std::format_string< Args... > fmt, Args &&...args) const
 输出warn日志
 
void log_error (std::format_string< Args... > fmt, Args &&...args) const
 输出error日志
 

成员类型定义说明

◆ task_type

using roboctrl::async::task_context::task_type = awaitable<>

在文件 async.hpp54 行定义.

构造及析构函数说明

◆ task_context()

task_context::task_context ( )
explicit

在文件 async.cpp5 行定义.

成员函数说明

◆ asio_context()

auto roboctrl::async::task_context::asio_context ( ) -> asio::io_context&
inline

获取asio的io_context。

在文件 async.hpp129 行定义.

◆ desc()

std::string roboctrl::async::task_context::desc ( ) const
inline

task_context的描述

在文件 async.hpp115 行定义.

◆ get_executor()

auto roboctrl::async::task_context::get_executor ( )
inline

获取asio的executor。

在文件 async.hpp122 行定义.

◆ init()

bool task_context::init ( task_context::info_type  _info)

初始化 task_context

在文件 async.cpp24 行定义.

◆ post()

template<typename Fn , typename... Args>
void roboctrl::async::task_context::post ( Fn &&  fn,
Args &&...  args 
)
inline

添加一个任务到上下文中执行。

模板参数
Fn任务类型
Args任务参数类型
参数
fn任务
args任务参数

示例:

roboctrl::post([](int a,int b){
std::print("{} + {} = {}\n",a,b,a+b);
},1,2);
auto post(Args &&... args)
添加一个任务到全局任务上下文中执行。
Definition async.hpp:167
asio::awaitable< T > awaitable
协程任务类型。
Definition async.hpp:42

在文件 async.hpp96 行定义.

◆ run()

void task_context::run ( )

开始运行任务上下文。

在文件 async.cpp13 行定义.

引用了 roboctrl::log::logable< task_context >::log_info().

◆ spawn()

void task_context::spawn ( task_context::task_type &&  task)

添加一个协程任务到上下文中执行。

参数
task任务

示例:

while(true){
std::print("hello");
co_await roboctrl::wait_for(1s);
}
}());
awaitable< void > wait_for(const duration &duration)
协程任务等待。
Definition async.hpp:202
auto spawn(task_context::task_type &&task)
添加一个协程任务到全局任务上下文中执行。
Definition async.hpp:151

在文件 async.cpp9 行定义.

◆ stop()

void task_context::stop ( )

在文件 async.cpp18 行定义.


该类的文档由以下文件生成: