跳转至

Class qqmusic::utils::AsyncExecutor

ClassList > qqmusic > utils > AsyncExecutor

全局调度器类

  • #include <async-executor.h>

Public Functions

Type Name
AsyncExecutor (const AsyncExecutor &) = delete
void async_exec (qqmusic::Task< T > task, CompletionCallback && callback)
异步执行任务, 并在任务结束后触发回调
void async_exec (qqmusic::Task< void > task, CompletionCallback && callback)
异步执行任务函数的void特化, 并在任务结束后触发回调
void async_exec (qqmusic::Task< T > task, CompletionCallback && callback, std::chrono::steady_clock::duration timeout, TimeoutCallback && timeout_callback)
异步执行任务函数, 带有超时限制, 并在任务结束后触发回调
void async_exec (qqmusic::Task< void > task, CompletionCallback && callback, std::chrono::steady_clock::duration timeout, TimeoutCallback && timeout_callback)
异步执行任务函数void特化, 带有超时限制. 并在任务结束后触发回调
AsyncExecutor & operator= (const AsyncExecutor &) = delete
void shutdown ()
auto when_all (std::vector< boost::asio::awaitable< T > > tasks)
等待任务列表中所有的任务执行完毕之后返回结果列表

Public Static Functions

Type Name
AsyncExecutor & get_instance ()
获取全局单例引用

Public Functions Documentation

function AsyncExecutor [1/2]

qqmusic::utils::AsyncExecutor::AsyncExecutor (
    const AsyncExecutor &
) = delete

function async_exec [1/4]

异步执行任务, 并在任务结束后触发回调

template<typename T, BOOST_ASIO_COMPLETION_TOKEN_FOR(void(T &&)) CompletionCallback>
inline void qqmusic::utils::AsyncExecutor::async_exec (
    qqmusic::Task< T > task,
    CompletionCallback && callback
) 

Parameters:

  • task 异步任务
  • callback 回调函数, 会将task的执行结果传递给回调函数 回调函数不返回任何值

function async_exec [2/4]

异步执行任务函数的void特化, 并在任务结束后触发回调

template<BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) CompletionCallback>
inline void qqmusic::utils::AsyncExecutor::async_exec (
    qqmusic::Task< void > task,
    CompletionCallback && callback
) 

Parameters:

  • task 异步任务
  • callback 回调函数, 会将task的执行结果传递给回调函数 回调函数不返回任何值

function async_exec [3/4]

异步执行任务函数, 带有超时限制, 并在任务结束后触发回调

template<typename T, BOOST_ASIO_COMPLETION_TOKEN_FOR(void(T &&)) CompletionCallback, BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) TimeoutCallback>
inline void qqmusic::utils::AsyncExecutor::async_exec (
    qqmusic::Task< T > task,
    CompletionCallback && callback,
    std::chrono::steady_clock::duration timeout,
    TimeoutCallback && timeout_callback
) 

Parameters:

  • task 异步任务
  • callback 回调函数, 会将task的执行结果传递给回调函数 回调函数不返回任何值
  • timeout 超时时间限制
  • timeout_callback 超时之后需要执行的回调函数

function async_exec [4/4]

异步执行任务函数void特化, 带有超时限制. 并在任务结束后触发回调

template<BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) CompletionCallback, BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) TimeoutCallback>
inline void qqmusic::utils::AsyncExecutor::async_exec (
    qqmusic::Task< void > task,
    CompletionCallback && callback,
    std::chrono::steady_clock::duration timeout,
    TimeoutCallback && timeout_callback
) 

Parameters:

  • task 异步任务
  • callback 回调函数, 会将task的执行结果传递给回调函数 回调函数不返回任何值
  • timeout 超时时间限制
  • timeout_callback 超时之后需要执行的回调函数

function operator=

AsyncExecutor & qqmusic::utils::AsyncExecutor::operator= (
    const AsyncExecutor &
) = delete

function shutdown

void qqmusic::utils::AsyncExecutor::shutdown () 

function when_all

等待任务列表中所有的任务执行完毕之后返回结果列表

template<typename T>
inline auto qqmusic::utils::AsyncExecutor::when_all (
    std::vector< boost::asio::awaitable< T > > tasks
) 

// 使用示例:
std::vector<Task<nlohmann::json>> tasks{}; // 给定任务列表
auto& executor = qqmusic::utils::AsyncExecutor::get_instance();
auto results = executor.when_all(std::move(tasks));
for (auto& result : results) {
    // handle the result ...
}

Parameters:

  • tasks 异步任务列表

Returns:

包含结果列表的任务boost::asio::awaitable<std::vector<T>>

@warn 原本任务的顺序和结果顺序不一定一致


Public Static Functions Documentation

function get_instance

获取全局单例引用

static AsyncExecutor & qqmusic::utils::AsyncExecutor::get_instance () 

Returns:

全局调度器实例引用



The documentation for this class was generated from the following file include/qqmusic/utils/async-executor.h