+template<typename F>
+static inline void post_to_main_thread_and_wait(F &&fun)
+{
+ std::promise<void> done_promise;
+ std::future<void> done = done_promise.get_future();
+ post_to_main_thread(std::move(fun));
+ post_to_main_thread([&done_promise] { done_promise.set_value(); });
+ done.wait();
+}
+