diff options
author | ishfb <ishfb@yandex-team.ru> | 2022-02-10 16:48:07 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:07 +0300 |
commit | 0170772a2dbf133f32e17ca137ff64790d43831f (patch) | |
tree | 68ce3ab477bcb9e09abf2b0a6e7b34287c53f0df /library/cpp/threading/future/legacy_future.h | |
parent | df6128370874866447314ec18d8e67fc7bde40b4 (diff) | |
download | ydb-0170772a2dbf133f32e17ca137ff64790d43831f.tar.gz |
Restoring authorship annotation for <ishfb@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/threading/future/legacy_future.h')
-rw-r--r-- | library/cpp/threading/future/legacy_future.h | 48 |
1 files changed, 24 insertions, 24 deletions
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_); - } - }; - -} + } + }; + +} |