poco异步等待ActiveResult

时间:2023-03-09 09:09:56
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;
}