From 0170772a2dbf133f32e17ca137ff64790d43831f Mon Sep 17 00:00:00 2001 From: ishfb <ishfb@yandex-team.ru> Date: Thu, 10 Feb 2022 16:48:07 +0300 Subject: Restoring authorship annotation for <ishfb@yandex-team.ru>. Commit 1 of 2. --- library/cpp/threading/future/legacy_future.h | 48 ++++++++++++++-------------- 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'library/cpp/threading/future/legacy_future.h') diff --git a/library/cpp/threading/future/legacy_future.h b/library/cpp/threading/future/legacy_future.h index 6f1eabad73..4cb446047b 100644 --- a/library/cpp/threading/future/legacy_future.h +++ b/library/cpp/threading/future/legacy_future.h @@ -1,25 +1,25 @@ -#pragma once - +#pragma once + #include "fwd.h" -#include "future.h" - +#include "future.h" + #include <util/thread/factory.h> #include <functional> -namespace NThreading { +namespace NThreading { template <typename TR, bool IgnoreException> class TLegacyFuture: public IThreadFactory::IThreadAble, TNonCopyable { public: typedef TR(TFunctionSignature)(); using TFunctionObjectType = std::function<TFunctionSignature>; using TResult = typename TFunctionObjectType::result_type; - + private: TFunctionObjectType Func_; TPromise<TResult> Result_; THolder<IThreadFactory::IThread> Thread_; - + public: inline TLegacyFuture(const TFunctionObjectType func, IThreadFactory* pool = SystemThreadFactory()) : Func_(func) @@ -27,24 +27,24 @@ namespace NThreading { , Thread_(pool->Run(this)) { } - + inline ~TLegacyFuture() override { this->Join(); } - + inline TResult Get() { this->Join(); return Result_.GetValue(); } - + private: inline void Join() { if (Thread_) { Thread_->Join(); Thread_.Destroy(); } - } - + } + template <typename Result, bool IgnoreException_> struct TExecutor { static void SetPromise(TPromise<Result>& promise, const TFunctionObjectType& func) { @@ -54,11 +54,11 @@ namespace NThreading { } catch (...) { } } else { - promise.SetValue(func()); - } - } + promise.SetValue(func()); + } + } }; - + template <bool IgnoreException_> struct TExecutor<void, IgnoreException_> { static void SetPromise(TPromise<void>& promise, const TFunctionObjectType& func) { @@ -69,15 +69,15 @@ namespace NThreading { } catch (...) { } } else { - func(); - promise.SetValue(); - } - } + func(); + promise.SetValue(); + } + } }; void DoExecute() override { TExecutor<TResult, IgnoreException>::SetPromise(Result_, Func_); - } - }; - -} + } + }; + +} -- cgit v1.2.3