Loading…
|
Translation changed |
|
|
String added in the repository |
|
Loading…
|
Translation changed |
|
|
String added in the repository |
|
An asynchronous operation begins with a call to an异步操作从调用 [@boost:/doc/html/boost_asio/reference/asynchronous_operations.html ['initiating function]], which starts the operation and returns to the caller immediately. This ['outstanding] asynchronous operation proceeds concurrently without blocking the caller. When the externally observable side effects are fully established, a movable function object known as a [@boost:/doc/html/boost_asio/reference/CompletionHandler.html ['completion handler]] provided in the initiating function call is queued for execution with the results, which may include the error code and other specific information. An asynchronous operation is said to be ['completed] after the completion handler is queued. The code that follows shows how some text may be written to a socket asynchronously, invoking a lambda when the operation is complete:发起函数]] 开始。该函数负责启动操作并立即返回,不会等待操作完成。随后,这个 [未完成] 的异步操作会在后台并发执行,不会阻塞调用者。当操作的外部可见效果全部产生后,发起函数中提供的一个可移动对象(称为 [@boost:/doc/html/boost_asio/reference/CompletionHandler.html [完成处理器]])会连同操作结果(例如错误码及其他信息)一起被放入队列,等待执行。完成处理器被放入队列的那一刻,就意味着该异步操作 [已完成]。下面的代码演示了如何异步地向套接字写入一段文本,并在操作完成时调用一个 lambda 函数: