Hi Igor, Cap'n Proto RPC is currently single-threaded. You can only use a capability client in the thread that created it. If you want to make requests from multiple threads, each thread will need to form its own request to the server. (This is arguably more efficient anyway since it avoids synchronization costs from a shared connection.)
For the second part of your question, you may want to look at kj::newPromiseAndFulfiller(). -Kenton On Sun, Mar 5, 2017 at 1:46 AM, igor Nikolaychuk <[email protected]> wrote: > Is it possible to run Cap'n Proto RPC client and use it from another > threads to perform asynchronous RPC calls? > I've written the following client behavior, how to make the code work if > it's possible? > > capnp::EzRpcClient client(argv[1], 5923); > auto& waitScope = client.getWaitScope(); > Directory::Client cap = client.getMain<Directory>(); > > std::thread([&]() { > while(true) { > auto request = cap.openRequest(); > request.setName("test"); > auto promise = request.send(); > promise.then([](capnp::Response<Directory::OpenResults>&& r) { > std::cout << r.getTest().cStr() << std::endl; > }); > sleep(1); > } > }).detach(); > > kj::NEVER_DONE.wait(waitScope) > > > Also I didn't find any example of asynchronous responding. How to implement > the following server behavior? > > > class DirectoryImpl final: public Directory::Server { > public: > kj::Promise<void> open(OpenContext context) override { > asio_io_service.post([=](){ > > // Fetching information on another thread > > capnproto_io_service.post([=](){ > > context.getResults().setFile("lol"); > > //TODO: Sending the result to the client > > }); > > }); > } > }; > > -- > You received this message because you are subscribed to the Google Groups > "Cap'n Proto" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > Visit this group at https://groups.google.com/group/capnproto. > -- You received this message because you are subscribed to the Google Groups "Cap'n Proto" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. Visit this group at https://groups.google.com/group/capnproto.
