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;
}
生活的残酷,让我们习惯了忘记疲倦,一直奔向远方,追寻着自己的梦想。