MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / loop

Function loop

Source/Common/Utils.cpp:170–194  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

168}
169
170std::function<bool(double)> loop(const std::function<Job()>& work) {
171 auto co = std::make_shared<std::optional<Job>>();
172 return std::function<bool(double)>([co, work](double) {
173 if (!*co) {
174 *co = work();
175 const auto& coroutine = co->value();
176 if (coroutine.promise().value || coroutine.done()) {
177 return true;
178 }
179 } else {
180 const auto& coroutine = co->value();
181 coroutine.resume();
182 if (coroutine.promise().exception) {
183 std::rethrow_exception(coroutine.promise().exception);
184 }
185 if (coroutine.promise().value) {
186 return true;
187 }
188 if (coroutine.done()) {
189 *co = std::nullopt;
190 }
191 }
192 return false;
193 });
194}
195
196void thread(const std::function<Job()>& work) {
197 SharedDirector.getScheduler()->schedule(once(work));

Callers 1

threadLoopFunction · 0.70

Calls 2

resumeMethod · 0.65
valueMethod · 0.45

Tested by

no test coverage detected