mirror of
https://github.com/latentPrion/libspinscale.git
synced 2026-08-12 23:48:22 +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/puppetApplication.cpp
|
||||||
src/runtime.cpp
|
src/runtime.cpp
|
||||||
src/callableTracer.cpp
|
src/callableTracer.cpp
|
||||||
|
src/multiOperationResultSet.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties(spinscale PROPERTIES
|
set_target_properties(spinscale PROPERTIES
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
#include <exception>
|
#include <exception>
|
||||||
|
|
||||||
namespace sscl {
|
namespace sscl {
|
||||||
|
namespace co {
|
||||||
|
struct Group;
|
||||||
|
} // namespace co
|
||||||
|
|
||||||
/** Plain aggregate for fan-out / fan-in results returned from coroutines. */
|
/** Plain aggregate for fan-out / fan-in results returned from coroutines. */
|
||||||
struct MultiOperationResultSet
|
struct MultiOperationResultSet
|
||||||
@@ -38,9 +41,29 @@ struct MultiOperationResultSetWithException
|
|||||||
memberFailureException(memberFailureExceptionIn)
|
memberFailureException(memberFailureExceptionIn)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
/** Summarize a settled Group into counts + aggregated member failure. */
|
||||||
|
explicit MultiOperationResultSetWithException(const co::Group &group);
|
||||||
|
|
||||||
bool hasMemberFailure() const
|
bool hasMemberFailure() const
|
||||||
{ return memberFailureException != nullptr; }
|
{ 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;
|
MultiOperationResultSet results;
|
||||||
std::exception_ptr memberFailureException = nullptr;
|
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