[ https://issues.apache.org/jira/browse/THRIFT-2075?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14142706#comment-14142706 ]
Konrad Grochowski commented on THRIFT-2075: ------------------------------------------- linked "implementation issue" > C++ async client project > ------------------------ > > Key: THRIFT-2075 > URL: https://issues.apache.org/jira/browse/THRIFT-2075 > Project: Thrift > Issue Type: New Feature > Components: C++ - Compiler, C++ - Library > Reporter: Konrad Grochowski > > What do you think about such iface for async c++ client? > {code} > service Serv > { > X fun(1: Y y) > } > {code} > {code} > class ServAsyncClient > { > boost::future<X> fun(const Y& y); > }; > {code} > 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: > {code} > 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; > } > // .... > }; > {code} > 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 -- This message was sent by Atlassian JIRA (v6.3.4#6332)