mirror of
https://github.com/latentPrion/libspinscale.git
synced 2026-06-23 19:48:32 +00:00
Don't auto-throw non-viral callee exceptions before callerLambda
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include <spinscale/spinLock.h>
|
#include <spinscale/spinLock.h>
|
||||||
#include <spinscale/co/coQutex.h>
|
#include <spinscale/co/coQutex.h>
|
||||||
|
#include <spinscale/co/nonViralCompletion.h>
|
||||||
#include <spinscale/co/promiseChainLink.h>
|
#include <spinscale/co/promiseChainLink.h>
|
||||||
#include <spinscale/co/promiseReturnOps.h>
|
#include <spinscale/co/promiseReturnOps.h>
|
||||||
#include <spinscale/co/returnValues.h>
|
#include <spinscale/co/returnValues.h>
|
||||||
@@ -126,12 +127,8 @@ struct NonPostingPromise
|
|||||||
<< std::this_thread::get_id()
|
<< std::this_thread::get_id()
|
||||||
<< " Non-viral non-posting: invoking callerLambda directly.\n";
|
<< " Non-viral non-posting: invoking callerLambda directly.\n";
|
||||||
#endif
|
#endif
|
||||||
if (calleePromise.returnValues.myExceptionPtr) {
|
auto callerLambda = std::move(calleePromise.callerLambda);
|
||||||
std::rethrow_exception(
|
callerLambda();
|
||||||
calleePromise.returnValues.myExceptionPtr);
|
|
||||||
}
|
|
||||||
|
|
||||||
calleePromise.callerLambda();
|
|
||||||
return std::noop_coroutine();
|
return std::noop_coroutine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
#ifndef NON_VIRAL_COMPLETION_H
|
||||||
|
#define NON_VIRAL_COMPLETION_H
|
||||||
|
|
||||||
|
#include <exception>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
namespace sscl::co {
|
||||||
|
|
||||||
|
class NonViralCompletion
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit NonViralCompletion(std::exception_ptr &exceptionPtr)
|
||||||
|
: exceptionPtr(exceptionPtr)
|
||||||
|
{}
|
||||||
|
|
||||||
|
bool hasException() const noexcept
|
||||||
|
{
|
||||||
|
return exceptionPtr != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void checkAndRethrowException() const
|
||||||
|
{
|
||||||
|
if (exceptionPtr)
|
||||||
|
{
|
||||||
|
std::rethrow_exception(exceptionPtr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::exception_ptr releaseException() noexcept
|
||||||
|
{
|
||||||
|
return std::exchange(exceptionPtr, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::exception_ptr &exceptionPtr;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace sscl::co
|
||||||
|
|
||||||
|
#endif // NON_VIRAL_COMPLETION_H
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include <spinscale/componentThread.h>
|
#include <spinscale/componentThread.h>
|
||||||
#include <spinscale/co/coQutex.h>
|
#include <spinscale/co/coQutex.h>
|
||||||
|
#include <spinscale/co/nonViralCompletion.h>
|
||||||
#include <spinscale/co/postTarget.h>
|
#include <spinscale/co/postTarget.h>
|
||||||
#include <spinscale/co/promiseChainLink.h>
|
#include <spinscale/co/promiseChainLink.h>
|
||||||
#include <spinscale/co/promiseReturnOps.h>
|
#include <spinscale/co/promiseReturnOps.h>
|
||||||
@@ -164,15 +165,12 @@ struct PostingPromise
|
|||||||
std::cout << "final_suspend" << ": " << std::this_thread::get_id()
|
std::cout << "final_suspend" << ": " << std::this_thread::get_id()
|
||||||
<< " Non-viral: posting callerLambda completion to callerIoContext.\n";
|
<< " Non-viral: posting callerLambda completion to callerIoContext.\n";
|
||||||
#endif
|
#endif
|
||||||
|
auto callerLambda = std::move(calleePromise.callerLambda);
|
||||||
boost::asio::post(
|
boost::asio::post(
|
||||||
calleePromise.callerIoContext,
|
calleePromise.callerIoContext,
|
||||||
[&calleeRef = calleePromise]()
|
[callerLambda = std::move(callerLambda)]() mutable
|
||||||
{
|
{
|
||||||
if (calleeRef.returnValues.myExceptionPtr) {
|
callerLambda();
|
||||||
std::rethrow_exception(calleeRef.returnValues.myExceptionPtr);
|
|
||||||
}
|
|
||||||
|
|
||||||
calleeRef.callerLambda();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user