/
githubmirror
/
nbs
Обзор
Документация
Войти
/
githubmirror
/
nbs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
library/cpp/threading/future/async.h
31 строка
1021 B
qkrorlqr
Initial NBS OpenSource export
28 апр 2023, 21:54
28 апр 2023, 21:54
783a858
Код
Авторство
О чём код?
#pragma once #include "future.h" #include <util/generic/function.h> #include <util/thread/pool.h> 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<T> unless T is TFuture<U>. * In this case the function returns TFuture<U>. * * If you want to use another queue for execution just write an overload, @see ExtensionExample * unittest. */ template <typename Func> TFuture<TFutureType<TFunctionResult<Func>>> Async(Func&& func, IThreadPool& queue) { auto promise = NewPromise<TFutureType<TFunctionResult<Func>>>(); auto lambda = [promise, func = std::forward<Func>(func)]() mutable { NImpl::SetValue(promise, func); }; queue.SafeAddFunc(std::move(lambda)); return promise.GetFuture(); } }