@@ -29,7 +29,29 @@ AGRPC_NAMESPACE_BEGIN()
2929/* *
3030 * @brief (experimental) Register a coroutine rpc handler for the given method
3131 *
32+ * The rpc handler will be invoked for every incoming request of this gRPC method. It must take `ServerRPC&` as
33+ * first argument and `ServerRPC::Request&` as second argument (only for unary and server-streaming rpcs). The ServerRPC
34+ * is automatically cancelled at the end of the rpc handler if `finish()` was not called earlier. The return value of
35+ * the rpc handler is `co_spawn`ed in a manner similar to:
36+ * `CoroutineTraits::co_spawn(executor, rpc_handler, completion_handler, function)`, where
37+ * `completion_handler` is created from `token`, `executor` the first argument passed to this function and `function`,
38+ * when invoked, starts waiting for the next rpc. Any arguments passed to `function` will be prepended to the call of
39+ * the rpc handler. The return type of `function` is `CoroutineTraits::ReturnType`, which must be a coroutine, and
40+ * `CoroutineTraits::completion_token` must produce an Asio compatible [completion
41+ * token](https://www.boost.org/doc/libs/1_86_0/doc/html/boost_asio/reference/asynchronous_operations.html#boost_asio.reference.asynchronous_operations.completion_tokens_and_handlers)
42+ * that, when used to initiate an asynchronous operation, returns an awaitable.
43+ *
44+ * This asynchronous operation runs forever unless it is cancelled, the rpc handler throws an exception or the server is
45+ * shutdown
46+ * ([grpc::Server::Shutdown](https://grpc.github.io/grpc/cpp/classgrpc_1_1_server_interface.html#a6a1d337270116c95f387e0abf01f6c6c)
47+ * is called). At which point it invokes the completion handler (passing forward the exception thrown by the request
48+ * handler, if any) after all coroutines produced by invoking the rpc handler complete.
49+ *
3250 * @tparam ServerRPC An instantiation of `agrpc::ServerRPC`
51+ * @tparam CoroutineTraits A class that provides functions for spawning the coroutine of each rpc. Example:
52+ *
53+ * @snippet coro_traits.hpp asio-coro-traits
54+ *
3355 * @param executor The executor used to handle each rpc
3456 * @param service The service associated with the gRPC method of the ServerRPC
3557 * @param rpc_handler A callable that produces a coroutine. The coroutine's return value is ignored.
0 commit comments