hello_loopless.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. //
  2. // Copyright (c) 2019 Ivan Baidakou (basiliscos) (the dot dmol at gmail dot com)
  3. //
  4. // Distributed under the MIT Software License
  5. //
  6. #include "rotor.hpp"
  7. #include <iostream>
  8. struct hello_actor : public rotor::actor_base_t {
  9. using rotor::actor_base_t::actor_base_t;
  10. void on_start(rotor::message_t<rotor::payload::start_actor_t> &) noexcept override {
  11. std::cout << "hello world\n";
  12. supervisor.do_shutdown();
  13. }
  14. };
  15. struct dummy_supervisor : public rotor::supervisor_t {
  16. using rotor::supervisor_t::supervisor_t;
  17. void start_timer(const rotor::pt::time_duration &, timer_id_t) noexcept override {}
  18. void cancel_timer(timer_id_t) noexcept override {}
  19. void start() noexcept override {}
  20. void shutdown() noexcept override {}
  21. void enqueue(rotor::message_ptr_t) noexcept override {}
  22. };
  23. int main() {
  24. rotor::system_context_t ctx{};
  25. auto timeout = boost::posix_time::milliseconds{500}; /* does not matter */
  26. rotor::supervisor_config_t cfg{timeout};
  27. auto sup = ctx.create_supervisor<dummy_supervisor>(nullptr, cfg);
  28. sup->create_actor<hello_actor>(timeout);
  29. sup->do_process();
  30. return 0;
  31. }