actorfm/bin/main.cpp
2022-10-23 19:14:18 +03:00

48 lines
1.1 KiB
C++

#include "actorfm.hpp"
#include "logger/logger.hpp"
using result_t = std::vector<int>;
struct message
{
result_t data;
};
class sorting : public actorfm::actor<message, result_t>
{
public:
result_t invoke(message ms, actorfm::actor<message, result_t>* ac = nullptr) override
{
result_t res;
std::sort(ms.data.begin(), ms.data.end());
if (ac)
{
std::future<result_t> fut = ac->expect(ms);
res = fut.get();
}
else
res = ms.data;
return res;
}
};
int main(int argc, char *argv[])
{
hack::log()("run example");
sorting sort;
message ms { result_t{ 1, 5, 7, 9, 2, 4, 6, 8, 1, 5, 7, 9, 2, 4, 6, 8, 1, 5, 7, 9, 2, 4, 6, 8, 1, 5, 7, 9, 2, 4, 6, 8, 1, 5, 7, 9, 2, 4, 6, 8, 1, 5, 7, 9, 2, 4, 6, 8, 10, 13, 12, 11 } };
actorfm::actor_controller::instance().set_actor(sort);
auto fut = sort.expect(ms);
hack::log(": ")("final result", fut.get());
actorfm::actor_controller::instance().remove_actor(sort);
actorfm::actor_controller::instance().destroy();
hack::log()("completed");
}