| 60 | event::ListenerPtr worker; |
| 61 | }; |
| 62 | ServerThreadExecutor::ServerThreadExecutor(std::string name, Duration maxOnceDuration, size_t checkPack) |
| 63 | : Executor(std::move(name)), |
| 64 | impl(std::make_unique<Impl>(std::make_shared<Impl::SharedImpl>())) { |
| 65 | impl->worker = event::EventBus::getInstance().emplaceListener<event::ServerLevelTickEvent>( |
| 66 | [name = getName(), maxOnceDuration, checkPack, weak = std::weak_ptr{impl->shared}](auto&&) { |
| 67 | auto impl = weak.lock(); |
| 68 | if (!impl) { |
| 69 | return; |
| 70 | } |
| 71 | auto begin = Clock::now(); |
| 72 | impl->update([&](auto& f, size_t i) { |
| 73 | try { |
| 74 | f(); |
| 75 | } catch (...) { |
| 76 | getLogger().error("Error in {}:", name); |
| 77 | error_utils::printCurrentException(getLogger()); |
| 78 | } |
| 79 | if (i % checkPack == 0 && Clock::now() - begin > maxOnceDuration) { |
| 80 | return false; |
| 81 | } |
| 82 | return true; |
| 83 | }); |
| 84 | }, |
| 85 | event::EventPriority::Low |
| 86 | ); |
| 87 | } |
| 88 | ServerThreadExecutor::~ServerThreadExecutor() { |
| 89 | event::EventBus::getInstance().removeListener<event::ServerLevelTickEvent>(impl->worker); |
| 90 | } |
nothing calls this directly
no test coverage detected