diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:17 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:17 +0300 |
commit | d3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch) | |
tree | dd4bd3ca0f36b817e96812825ffaf10d645803f2 /library/cpp/threading/future/legacy_future.h | |
parent | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff) | |
download | ydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.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 | 104 |
1 files changed, 52 insertions, 52 deletions
diff --git a/library/cpp/threading/future/legacy_future.h b/library/cpp/threading/future/legacy_future.h index c699aadf5c..6f1eabad73 100644 --- a/library/cpp/threading/future/legacy_future.h +++ b/library/cpp/threading/future/legacy_future.h @@ -4,79 +4,79 @@ #include "future.h" #include <util/thread/factory.h> - + #include <functional> - + 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; + public: + typedef TR(TFunctionSignature)(); + using TFunctionObjectType = std::function<TFunctionSignature>; + using TResult = typename TFunctionObjectType::result_type; - private: - TFunctionObjectType Func_; - TPromise<TResult> Result_; + private: + TFunctionObjectType Func_; + TPromise<TResult> Result_; THolder<IThreadFactory::IThread> Thread_; - public: + public: inline TLegacyFuture(const TFunctionObjectType func, IThreadFactory* pool = SystemThreadFactory()) - : Func_(func) - , Result_(NewPromise<TResult>()) - , Thread_(pool->Run(this)) - { - } + : Func_(func) + , Result_(NewPromise<TResult>()) + , Thread_(pool->Run(this)) + { + } - inline ~TLegacyFuture() override { - this->Join(); - } + inline ~TLegacyFuture() override { + this->Join(); + } - inline TResult Get() { - this->Join(); - return Result_.GetValue(); - } + inline TResult Get() { + this->Join(); + return Result_.GetValue(); + } - private: - inline void Join() { - if (Thread_) { - Thread_->Join(); - Thread_.Destroy(); - } + 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) { - if (IgnoreException_) { - try { - promise.SetValue(func()); - } catch (...) { - } - } else { + template <typename Result, bool IgnoreException_> + struct TExecutor { + static void SetPromise(TPromise<Result>& promise, const TFunctionObjectType& func) { + if (IgnoreException_) { + try { + promise.SetValue(func()); + } catch (...) { + } + } else { promise.SetValue(func()); } } - }; + }; - template <bool IgnoreException_> - struct TExecutor<void, IgnoreException_> { - static void SetPromise(TPromise<void>& promise, const TFunctionObjectType& func) { - if (IgnoreException_) { - try { - func(); - promise.SetValue(); - } catch (...) { - } - } else { + template <bool IgnoreException_> + struct TExecutor<void, IgnoreException_> { + static void SetPromise(TPromise<void>& promise, const TFunctionObjectType& func) { + if (IgnoreException_) { + try { + func(); + promise.SetValue(); + } catch (...) { + } + } else { func(); promise.SetValue(); } } - }; - - void DoExecute() override { - TExecutor<TResult, IgnoreException>::SetPromise(Result_, Func_); + }; + + void DoExecute() override { + TExecutor<TResult, IgnoreException>::SetPromise(Result_, Func_); } }; |