diff options
author | dronimal <dronimal@yandex-team.ru> | 2022-02-10 16:47:14 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:14 +0300 |
commit | 2f2cfabf97857f24c4af02eed4ed9b5a14655bac (patch) | |
tree | d1555d5568cdcab2fecc314cc22de71b9850d33a /library/cpp/threading | |
parent | 55160ef791e40ea123fd56456eeeaf648ef93fc0 (diff) | |
download | ydb-2f2cfabf97857f24c4af02eed4ed9b5a14655bac.tar.gz |
Restoring authorship annotation for <dronimal@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/threading')
-rw-r--r-- | library/cpp/threading/future/core/future-inl.h | 40 | ||||
-rw-r--r-- | library/cpp/threading/future/future_ut.cpp | 42 |
2 files changed, 41 insertions, 41 deletions
diff --git a/library/cpp/threading/future/core/future-inl.h b/library/cpp/threading/future/core/future-inl.h index 5fd4296a93..c7b15fdb02 100644 --- a/library/cpp/threading/future/core/future-inl.h +++ b/library/cpp/threading/future/core/future-inl.h @@ -451,30 +451,30 @@ namespace NThreading { } template <typename T> - inline void SetValueImpl(TPromise<T>& promise, const TFuture<T>& future, - std::enable_if_t<!std::is_void<T>::value, bool> = false) { + inline void SetValueImpl(TPromise<T>& promise, const TFuture<T>& future, + std::enable_if_t<!std::is_void<T>::value, bool> = false) { future.Subscribe([=](const TFuture<T>& f) mutable { - T const* value; + T const* value; try { - value = &f.GetValue(); + value = &f.GetValue(); } catch (...) { promise.SetException(std::current_exception()); - return; + return; } - promise.SetValue(*value); + promise.SetValue(*value); }); } - template <typename T> - inline void SetValueImpl(TPromise<void>& promise, const TFuture<T>& future) { - future.Subscribe([=](const TFuture<T>& f) mutable { + template <typename T> + inline void SetValueImpl(TPromise<void>& promise, const TFuture<T>& future) { + future.Subscribe([=](const TFuture<T>& f) mutable { try { f.TryRethrow(); } catch (...) { promise.SetException(std::current_exception()); - return; + return; } - promise.SetValue(); + promise.SetValue(); }); } @@ -483,10 +483,10 @@ namespace NThreading { try { SetValueImpl(promise, func()); } catch (...) { - const bool success = promise.TrySetException(std::current_exception()); - if (Y_UNLIKELY(!success)) { - throw; - } + const bool success = promise.TrySetException(std::current_exception()); + if (Y_UNLIKELY(!success)) { + throw; + } } } @@ -497,9 +497,9 @@ namespace NThreading { func(); } catch (...) { promise.SetException(std::current_exception()); - return; + return; } - promise.SetValue(); + promise.SetValue(); } } @@ -631,7 +631,7 @@ namespace NThreading { inline TFuture<void> TFuture<T>::IgnoreResult() const { auto promise = NewPromise(); Subscribe([=](const TFuture<T>& future) mutable { - NImpl::SetValueImpl(promise, future); + NImpl::SetValueImpl(promise, future); }); return promise; } @@ -734,9 +734,9 @@ namespace NThreading { future.TryRethrow(); } catch (...) { promise.SetException(std::current_exception()); - return; + return; } - promise.SetValue(value); + promise.SetValue(value); }); return promise; } diff --git a/library/cpp/threading/future/future_ut.cpp b/library/cpp/threading/future/future_ut.cpp index 05950a568d..68a6779098 100644 --- a/library/cpp/threading/future/future_ut.cpp +++ b/library/cpp/threading/future/future_ut.cpp @@ -239,27 +239,27 @@ namespace { UNIT_ASSERT_EXCEPTION(promise.TryRethrow(), TCustomException); } - Y_UNIT_TEST(ShouldRethrowCallbackException) { - TPromise<int> promise = NewPromise<int>(); - TFuture<int> future = promise.GetFuture(); - future.Subscribe([](const TFuture<int>&) { - throw TCustomException(); - }); - - UNIT_ASSERT_EXCEPTION(promise.SetValue(123), TCustomException); - } - - Y_UNIT_TEST(ShouldRethrowCallbackExceptionIgnoreResult) { - TPromise<int> promise = NewPromise<int>(); - TFuture<void> future = promise.GetFuture().IgnoreResult(); - future.Subscribe([](const TFuture<void>&) { - throw TCustomException(); - }); - - UNIT_ASSERT_EXCEPTION(promise.SetValue(123), TCustomException); - } - - + Y_UNIT_TEST(ShouldRethrowCallbackException) { + TPromise<int> promise = NewPromise<int>(); + TFuture<int> future = promise.GetFuture(); + future.Subscribe([](const TFuture<int>&) { + throw TCustomException(); + }); + + UNIT_ASSERT_EXCEPTION(promise.SetValue(123), TCustomException); + } + + Y_UNIT_TEST(ShouldRethrowCallbackExceptionIgnoreResult) { + TPromise<int> promise = NewPromise<int>(); + TFuture<void> future = promise.GetFuture().IgnoreResult(); + future.Subscribe([](const TFuture<void>&) { + throw TCustomException(); + }); + + UNIT_ASSERT_EXCEPTION(promise.SetValue(123), TCustomException); + } + + Y_UNIT_TEST(ShouldWaitExceptionOrAll) { TPromise<void> promise1 = NewPromise(); TPromise<void> promise2 = NewPromise(); |