#pragma once #include "future.h" #include #include namespace NThreading { /** * @brief Asynchronously executes @arg func in @arg queue returning a future for the result. * * @arg func should be a callable object with signature T(). * @arg queue where @arg will be executed * @returns For @arg func with signature T() the function returns TFuture unless T is TFuture. * In this case the function returns TFuture. * * If you want to use another queue for execution just write an overload, @see ExtensionExample * unittest. */ template TFuture>> Async(Func&& func, IThreadPool& queue) { auto promise = NewPromise>>(); auto lambda = [promise, func = std::forward(func)]() mutable { NImpl::SetValue(promise, func); }; queue.SafeAddFunc(std::move(lambda)); return promise.GetFuture(); } }