Details
-
New Feature
-
Status: Open
-
Major
-
Resolution: Unresolved
-
None
-
None
-
None
Description
What do you think about such iface for async c++ client?
service Serv { X fun(1: Y y) }
class ServAsyncClient { boost::future<X> fun(const Y& y); };
it could be implemented as a wrapper around "normal" client - just a blocking queue of boost::package_tasks and one thread executing it one by one.
This would work best with C++11 support (move semantics and lambdas could be used).
I've made wrapper for generated clients but such wrapper requires a lot of hand work
example:
class AsyncClient { public: AsyncClient(SyncClient* cli) : cli(cli) {} boost::future<X> fun(const Y& y) { addTask([this, y]() { return cli->fun(y); }); } private: blocking_queue<boost::function<void()> queue; template<typename Functor> boost::future<typename boost::result_of<Functor()>::type> addTask(Functor&& functor) { typedef typename boost::result_of<Functor()>::type result_type; typedef typename boost::packaged_task<result_type> task_type; typedef typename boost::shared_ptr<task_type> ptr_type; ptr_type ptr(new boost::packaged_task<result_type>(std::move(functor))); auto f = ptr->get_future(); queue.push_back([ptr]{ (*ptr)(); }); return f; } // .... };
originally I used boost::asio, which enables me to schedules some tasks to be executed periodically (like ping) etc.
I haven't tested it yet enough but I could look into possibilities of adding new option to thrift compiler if such contribution would be anticipated
I can also send my boost.asio based wrapper for anyone who would like to write own async wrapper
Attachments
Issue Links
- is related to
-
THRIFT-579 Alternative ASIO based fully async client/server for C++
- Open
- relates to
-
THRIFT-2717 C++V2 generator/library
- Open