You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Konrad Grochowski (JIRA)" <ji...@apache.org> on 2013/06/29 17:19:19 UTC
[jira] [Created] (THRIFT-2075) C++ async client project
Konrad Grochowski created THRIFT-2075:
-----------------------------------------
Summary: C++ async client project
Key: THRIFT-2075
URL: https://issues.apache.org/jira/browse/THRIFT-2075
Project: Thrift
Issue Type: Improvement
Components: 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 is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira