Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-2075

C++ async client project

    XMLWordPrintableJSON

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

          Activity

            People

              Unassigned Unassigned
              hcorg Konrad Grochowski
              Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: