Compare commits

...
Author SHA1 Message Date
admin 6b9afab26d different async 2025-08-15 06:43:19 -07:00
@@ -994,8 +994,8 @@ auto CalcOne(
&settingsGetter,
&allCastleCoords,
&apdCache,
&alCache]() -> ScoreValue {
auto lookaheadFuture = BasicLookaheadCalculator(
&alCache]() -> std::future<ScoreValue> {
return BasicLookaheadCalculator(
pid,
isDefender,
remainingLookahead,
@@ -1007,16 +1007,20 @@ auto CalcOne(
allCastleCoords,
apdCache,
alCache);
return lookaheadFuture.get();
};
#if MULTITHREAD
returnValue.lookaheadScore = std::async(std::launch::async, lookaheadLambda);
// Use async to run the lambda in parallel, then chain the resulting future
auto futureOfFuture = std::async(std::launch::async, lookaheadLambda);
returnValue.lookaheadScore = std::async(
std::launch::deferred,
[futureOfFuture = std::move(futureOfFuture)]() mutable -> ScoreValue {
auto innerFuture = futureOfFuture.get();
return innerFuture.get();
});
#else
std::promise<ScoreValue> p;
returnValue.lookaheadScore = p.get_future();
auto lambdaResult = lookaheadLambda();
p.set_value(lambdaResult);
// In single-threaded mode, just call the lambda directly
returnValue.lookaheadScore = lookaheadLambda();
#endif
}