diff options
author | nga <nga@yandex-team.ru> | 2022-02-10 16:48:09 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:09 +0300 |
commit | c2a1af049e9deca890e9923abe64fe6c59060348 (patch) | |
tree | b222e5ac2e2e98872661c51ccceee5da0d291e13 /library/cpp/messagebus/async_result.h | |
parent | 1f553f46fb4f3c5eec631352cdd900a0709016af (diff) | |
download | ydb-c2a1af049e9deca890e9923abe64fe6c59060348.tar.gz |
Restoring authorship annotation for <nga@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/messagebus/async_result.h')
-rw-r--r-- | library/cpp/messagebus/async_result.h | 88 |
1 files changed, 44 insertions, 44 deletions
diff --git a/library/cpp/messagebus/async_result.h b/library/cpp/messagebus/async_result.h index 05a1a70f16..d24dde284a 100644 --- a/library/cpp/messagebus/async_result.h +++ b/library/cpp/messagebus/async_result.h @@ -1,54 +1,54 @@ -#pragma once - -#include <util/generic/maybe.h> -#include <util/generic/noncopyable.h> +#pragma once + +#include <util/generic/maybe.h> +#include <util/generic/noncopyable.h> #include <util/system/condvar.h> #include <util/system/mutex.h> #include <util/system/yassert.h> #include <functional> - -// probably this thing should have been called TFuture -template <typename T> -class TAsyncResult : TNonCopyable { -private: - TMutex Mutex; - TCondVar CondVar; - - TMaybe<T> Result; - - typedef void TOnResult(const T&); - + +// probably this thing should have been called TFuture +template <typename T> +class TAsyncResult : TNonCopyable { +private: + TMutex Mutex; + TCondVar CondVar; + + TMaybe<T> Result; + + typedef void TOnResult(const T&); + std::function<TOnResult> OnResult; - -public: - void SetResult(const T& result) { - TGuard<TMutex> guard(Mutex); + +public: + void SetResult(const T& result) { + TGuard<TMutex> guard(Mutex); Y_VERIFY(!Result, "cannot set result twice"); - Result = result; - CondVar.BroadCast(); - - if (!!OnResult) { - OnResult(result); - } - } - - const T& GetResult() { - TGuard<TMutex> guard(Mutex); - while (!Result) { - CondVar.Wait(Mutex); - } - return *Result; - } - - template <typename TFunc> + Result = result; + CondVar.BroadCast(); + + if (!!OnResult) { + OnResult(result); + } + } + + const T& GetResult() { + TGuard<TMutex> guard(Mutex); + while (!Result) { + CondVar.Wait(Mutex); + } + return *Result; + } + + template <typename TFunc> void AndThen(const TFunc& onResult) { - TGuard<TMutex> guard(Mutex); - if (!!Result) { - onResult(*Result); - } else { + TGuard<TMutex> guard(Mutex); + if (!!Result) { + onResult(*Result); + } else { Y_ASSERT(!OnResult); OnResult = std::function<TOnResult>(onResult); - } - } -}; + } + } +}; |