X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=shared%2Fpost_to_main_thread.h;h=080ed51e5f4fc2279d9a1f60d73192e592167e3c;hb=b2313d869262960aa3bcaaf3f45f2a3b90d1fc18;hp=0462c7b67ab55f232f4de9c556e51033c38541ca;hpb=eeda8995329601f9f4e35047358400833eeae68e;p=nageru diff --git a/shared/post_to_main_thread.h b/shared/post_to_main_thread.h index 0462c7b..080ed51 100644 --- a/shared/post_to_main_thread.h +++ b/shared/post_to_main_thread.h @@ -3,6 +3,7 @@ #include #include +#include #include // http://stackoverflow.com/questions/21646467/how-to-execute-a-functor-in-a-given-thread-in-qt-gcd-style @@ -13,4 +14,14 @@ static inline void post_to_main_thread(F &&fun) QObject::connect(&signalSource, &QObject::destroyed, qApp, std::move(fun)); } +template +static inline void post_to_main_thread_and_wait(F &&fun) +{ + std::promise done_promise; + std::future done = done_promise.get_future(); + post_to_main_thread(std::move(fun)); + post_to_main_thread([&done_promise] { done_promise.set_value(); }); + done.wait(); +} + #endif // !defined(_POST_TO_MAIN_THREAD_H)