YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
result.cpp
Go to the documentation of this file.
2
3namespace yaclib {
4
5template class Result<>;
6
7const std::exception_ptr& StopPtr() noexcept {
8 // yaclib objects must not have static storage duration:
9 // e.g. a Promise destroyed during static destruction would cancel after this is destroyed
10 static const std::exception_ptr stop = std::make_exception_ptr(StopException{});
11 return stop;
12}
13
14bool IsStop(const std::exception_ptr& error) noexcept {
15 if (error == nullptr) {
16 return false;
17 }
18 if (error == StopPtr()) {
19 return true;
20 }
21 try {
22 std::rethrow_exception(error);
23 } catch (const StopException&) {
24 return true;
25 } catch (...) {
26 return false;
27 }
28}
29
30} // namespace yaclib
Contract< V, T > MakeContract()
Creates related future and promise.
Definition contract.hpp:25
bool IsStop(const std::exception_ptr &error) noexcept
Check if error represents cancellation,.
Definition result.cpp:14
const std::exception_ptr & StopPtr() noexcept
Cached std::exception_ptr with StopException, copy is cheap and never allocates.
Definition result.cpp:7
Exception that represents cancellation of an async operation,.
Definition result.hpp:27