mirror of
https://github.com/latentPrion/libspinscale.git
synced 2026-08-12 15:42:10 +00:00
Summarize and merge MultiOperationResultSetWithException from settled Groups.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -87,6 +87,7 @@ add_library(spinscale SHARED
|
||||
src/puppetApplication.cpp
|
||||
src/runtime.cpp
|
||||
src/callableTracer.cpp
|
||||
src/multiOperationResultSet.cpp
|
||||
)
|
||||
|
||||
set_target_properties(spinscale PROPERTIES
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
#include <exception>
|
||||
|
||||
namespace sscl {
|
||||
namespace co {
|
||||
struct Group;
|
||||
} // namespace co
|
||||
|
||||
/** Plain aggregate for fan-out / fan-in results returned from coroutines. */
|
||||
struct MultiOperationResultSet
|
||||
@@ -38,9 +41,29 @@ struct MultiOperationResultSetWithException
|
||||
memberFailureException(memberFailureExceptionIn)
|
||||
{}
|
||||
|
||||
/** Summarize a settled Group into counts + aggregated member failure. */
|
||||
explicit MultiOperationResultSetWithException(const co::Group &group);
|
||||
|
||||
bool hasMemberFailure() const
|
||||
{ return memberFailureException != nullptr; }
|
||||
|
||||
/** Combine this result set with another phase's counts and exception. */
|
||||
MultiOperationResultSetWithException mergeWith(
|
||||
const MultiOperationResultSetWithException &other) const
|
||||
{
|
||||
std::exception_ptr memberFailure = memberFailureException;
|
||||
if (!memberFailure && other.hasMemberFailure()) {
|
||||
memberFailure = other.memberFailureException;
|
||||
}
|
||||
|
||||
return MultiOperationResultSetWithException(
|
||||
MultiOperationResultSet(
|
||||
results.nTotal + other.results.nTotal,
|
||||
results.nSucceeded + other.results.nSucceeded,
|
||||
results.nFailed + other.results.nFailed),
|
||||
memberFailure);
|
||||
}
|
||||
|
||||
MultiOperationResultSet results;
|
||||
std::exception_ptr memberFailureException = nullptr;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
#include <boostAsioLinkageFix.h>
|
||||
|
||||
#include <spinscale/multiOperationResultSet.h>
|
||||
#include <spinscale/co/group.h>
|
||||
|
||||
namespace sscl {
|
||||
|
||||
MultiOperationResultSetWithException::MultiOperationResultSetWithException(
|
||||
const co::Group &group)
|
||||
{
|
||||
unsigned int nSucceeded = 0;
|
||||
unsigned int nFailed = 0;
|
||||
using SettlementType = co::Group::SettlementDescriptor::TypeE;
|
||||
|
||||
for (const auto &desc : group.s.rsrc.settlements)
|
||||
{
|
||||
if (desc.type == SettlementType::EXCEPTION_THROWN) {
|
||||
nFailed++;
|
||||
}
|
||||
else {
|
||||
nSucceeded++;
|
||||
}
|
||||
}
|
||||
|
||||
results = MultiOperationResultSet(
|
||||
static_cast<unsigned int>(group.s.rsrc.settlements.size()),
|
||||
nSucceeded,
|
||||
nFailed);
|
||||
|
||||
if (nFailed > 0) {
|
||||
memberFailureException = group.captureAggregatedGroupExceptions();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sscl
|
||||
Reference in New Issue
Block a user