diff --git a/include/fc/thread/thread.hpp b/include/fc/thread/thread.hpp index 040d877..bb82710 100644 --- a/include/fc/thread/thread.hpp +++ b/include/fc/thread/thread.hpp @@ -206,6 +206,22 @@ namespace fc { return fc::thread::current().schedule( fc::forward(f), t, desc, prio ); } + /** + * Call f() in thread t and block the current thread until it returns. + * + * If t is null, simply execute f in the current thread. + */ + template + auto sync_call( thread* t, Functor&& f, const char* desc FC_TASK_NAME_DEFAULT_ARG, priority prio = priority()) -> decltype(f()) + { + if( t == nullptr ) + return f(); + + typedef decltype(f()) Result; + future r = t->async( f, desc, prio ); + return r.wait(); + } + } // end namespace fc #ifdef _MSC_VER