38 static void defer_for(rpp::schedulers::duration duration, Fn&& fn, Handler&& handler, Args&&... args)
40 const auto application = QCoreApplication::instance();
43 handler.on_error(std::make_exception_ptr(
utils::no_active_qapplication{
"Pointer to application is null. Create QApplication before using main_thread_scheduler!"}));
47 QTimer::singleShot(std::chrono::duration_cast<std::chrono::milliseconds>(std::max(rpp::schedulers::duration{}, duration)), application, [fn = std::forward<Fn>(fn), handler = std::forward<Handler>(handler), ... args = std::forward<Args>(args)]()
mutable {
48 if (!handler.is_disposed())
49 invoke(std::move(fn), std::move(handler), std::move(args)...);
53 static rpp::schedulers::time_point now() {
return rpp::schedulers::clock_type::now(); }
57 static void invoke(Fn&& fn, Handler&& handler, Args&&... args)
59 if (
const auto new_duration = fn(handler, args...))
60 defer_for(new_duration->value, std::forward<Fn>(fn), std::forward<Handler>(handler), std::forward<Args>(args)...);
64 static void invoke(Fn&& fn, Handler&& handler, Args&&... args)
66 const auto now = rpp::schedulers::clock_type::now();
67 if (
const auto new_duration = fn(handler, args...))
68 defer_for(now + new_duration->value - rpp::schedulers::clock_type::now(), std::forward<Fn>(fn), std::forward<Handler>(handler), std::forward<Args>(args)...);
72 static void invoke(Fn&& fn, Handler&& handler, Args&&... args)
74 if (
const auto new_tp = fn(handler, args...))
75 defer_for(new_tp->value - rpp::schedulers::clock_type::now(), std::forward<Fn>(fn), std::forward<Handler>(handler), std::forward<Args>(args)...);
80 static auto create_worker()
Schedule provided schedulables to main GUI QT thread (where QApplication placed)
Definition main_thread.hpp:32