diff options
author | ishfb <ishfb@yandex-team.ru> | 2022-02-10 16:48:08 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:08 +0300 |
commit | 069c69f58fd78de3cf2e6eb2304047281e21fb65 (patch) | |
tree | b222e5ac2e2e98872661c51ccceee5da0d291e13 /library/cpp/threading/future/legacy_future.h | |
parent | 0170772a2dbf133f32e17ca137ff64790d43831f (diff) | |
download | ydb-069c69f58fd78de3cf2e6eb2304047281e21fb65.tar.gz |
Restoring authorship annotation for <ishfb@yandex-team.ru>. Commit 2 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 4cb446047b..6f1eabad73 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_); - } - }; - -} + } + }; + +} |