poco异步等待ActiveResult

#include "Poco/ActiveMethod.h"
#include "Poco/ActiveResult.h"
#include <utility>
#include <iostream>

using Poco::ActiveMethod;
using Poco::ActiveResult;

class ActiveAdder
{
public:
    ActiveAdder(): add(this, &ActiveAdder::addImpl)
    {
    }

    ActiveMethod<int, std::pair<int, int>, ActiveAdder> add;

private:
    int addImpl(const std::pair<int, int>& args)
    {
        return args.first + args.second;
    }
};

int main(int argc, char** argv)
{
    ActiveAdder adder;

    ActiveResult<int> sum = adder.add(std::make_pair(1, 2));
    // do other things
    for(int i=0;i<10;++i)
        std::cout<<i+1<<std::endl;
//    sum.wait();
    while(sum.available())
        break;
    std::cout << sum.data() << std::endl;

    return 0;
}

posted @ 2015-11-16 17:27  Arikes  阅读(453)  评论(0编辑  收藏  举报