| 807 | // TODO: Add SFINAE overloads for functors returning void or a non-Future type. |
| 808 | template <class F> |
| 809 | ThreadFuture<decltype(std::declval<F>()().getValue())> onMainThread(F f) { |
| 810 | Promise<Void> signal; |
| 811 | auto returnValue = new ThreadSingleAssignmentVar<decltype(std::declval<F>()().getValue())>(); |
| 812 | returnValue->addref(); // For the ThreadFuture we return |
| 813 | // TODO: Is this cancellation logic actually needed? |
| 814 | Future<Void> cancelFuture = internal_thread_helper::doOnMainThread<decltype(std::declval<F>()().getValue()), F>( |
| 815 | signal.getFuture(), f, returnValue); |
| 816 | returnValue->setCancel(std::move(cancelFuture)); |
| 817 | g_network->onMainThread(std::move(signal), TaskPriority::DefaultOnMainThread); |
| 818 | return ThreadFuture<decltype(std::declval<F>()().getValue())>(returnValue); |
| 819 | } |
| 820 | |
| 821 | template <class V> |
| 822 | class ThreadSafeAsyncVar : NonCopyable, public ThreadSafeReferenceCounted<ThreadSafeAsyncVar<V>> { |
no test coverage detected