template< typename WaitToken = default_completion_token_t<executor_type>> DEDUCED async_wait( wait_type w, WaitToken && token = default_completion_token_t< executor_type >());
此函数用于执行异步等待,以使描述符进入可读、可写或错误条件状态。它是 异步操作 的发起函数,并且始终立即返回。
指定所需的描述符状态。
将用于生成完成处理程序的 完成令牌,该处理程序将在等待完成时被调用。可能的完成令牌包括 use_future
、use_awaitable
、yield_context
,或者具有正确完成签名的函数对象。完成处理程序的函数签名必须是
void handler( const boost::system::error_code& error // Result of operation. );
无论异步操作是立即完成还是未立即完成,都不会在此函数内调用完成处理程序。在立即完成的情况下,处理程序的调用将以等同于使用 async_immediate
的方式执行。
void(boost::system::error_code)
void wait_handler(const boost::system::error_code& error) { if (!error) { // Wait succeeded. } } ... boost::asio::posix::stream_descriptor descriptor(my_context); ... descriptor.async_wait( boost::asio::posix::stream_descriptor::wait_read, wait_handler);
此异步操作支持以下 cancellation_type
值的取消
cancellation_type::terminal
cancellation_type::partial
cancellation_type::total