MCPcopy Create free account
hub / github.com/LiteLDev/LeviLamina / ServerThreadExecutor

Method ServerThreadExecutor

src/ll/api/thread/ServerThreadExecutor.cpp:62–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60 event::ListenerPtr worker;
61};
62ServerThreadExecutor::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}
88ServerThreadExecutor::~ServerThreadExecutor() {
89 event::EventBus::getInstance().removeListener<event::ServerLevelTickEvent>(impl->worker);
90}

Callers

nothing calls this directly

Calls 4

printCurrentExceptionFunction · 0.85
lockMethod · 0.45
updateMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected