diff --git a/Include/Aurora/Async/AuFutures.hpp b/Include/Aurora/Async/AuFutures.hpp index 0b02f10d..d81a1e95 100644 --- a/Include/Aurora/Async/AuFutures.hpp +++ b/Include/Aurora/Async/AuFutures.hpp @@ -345,7 +345,9 @@ struct AuWaterfall : AuEnableSharedFromThis if (this->bDone) { - if (this->bFailed) + auto [bSendSuccess, bSendFail] = this->GetDispatch(true); + + if (bSendFail) { onFailure(); } @@ -364,7 +366,9 @@ struct AuWaterfall : AuEnableSharedFromThis if (this->bDone) { - if (!this->bFailed) + auto [bSendSuccess, bSendFail] = this->GetDispatch(true); + + if (bSendSuccess) { onSuccess(); } @@ -384,25 +388,41 @@ struct AuWaterfall : AuEnableSharedFromThis private: - void FireDelayed() + AuPair GetDispatch(bool bForce = false) { bool bSendSuccess {}; bool bSendFail {}; - if ((this->bFailOnAny && bool(this->uCountOfFailed)) || (this->uCountOfFailed == this->uCount)) { - bSendFail = bool(this->onFailure.size()); + bSendFail = bool(this->onFailure.size()) || bForce; } else if ((!this->bFailOnAny || !this->uCountOfFailed) && this->uCountOfComplete == this->uCount) { - bSendSuccess = bool(this->onSuccess.size()); + bSendSuccess = bool(this->onSuccess.size()) || bForce; } else if (!this->bFailOnAny && ((this->uCountOfComplete + this->uCountOfFailed) == this->uCount)) { - bSendSuccess = bool(this->onSuccess.size()); + bSendSuccess = bool(this->onSuccess.size()) || bForce; + } + + return AuMakePair(bSendSuccess, bSendFail); + } + + void FireDelayed() + { + auto [bSendSuccess, bSendFail] = this->GetDispatch(false); + + if (!bSendSuccess && !bSendFail) + { + return; + } + + if (bSendFail) + { + this->bFailed = true; } if (AuExchange(this->bDone, true)) @@ -417,7 +437,6 @@ private: } else if (bSendFail) { - this->bFailed = true; this->pFuture->Fail(); } }