[*] Coroutine interopability: failed AuFutures are now indicated via AuOptionalEx returned by co_await

This commit is contained in:
Reece Wilson 2023-07-08 12:53:31 +01:00
parent edcc9efac3
commit 730d338c17

View File

@ -199,6 +199,11 @@ protected:
return this->bComplete || this->bFailed;
}
bool IsFailed()
{
return this->bFailed;
}
AuThreading::IWaitable *GetWaitOnInterface()
{
return this->event.AsPointer();
@ -618,7 +623,13 @@ namespace __detail
template<typename A, typename B>
static bool IsFinished(AuFuture<A, B> &future)
{
return future.bComplete || future.bFailed;
return future.IsFinished();
}
template<typename A, typename B>
static bool IsFailed(AuFuture<A, B> &future)
{
return future.IsFailed();
}
template<typename A, typename B>
@ -729,20 +740,37 @@ namespace __detail
template <typename T>
void await_suspend(T h)
{
pFuture->OnComplete([=]()
pFuture->OnComplete([=](const A &)
{
h.resume();
});
pFuture->OnFailure([=]()
if constexpr (!AuIsVoid_v<B>)
{
h.resume();
});
pFuture->OnFailure([=](const B &)
{
h.resume();
});
}
else
{
pFuture->OnFailure([=]()
{
h.resume();
});
}
}
A await_resume()
AuOptionalEx<A> await_resume()
{
return __detail::FutureAccessor::GetValue(*pFuture.get());
auto &refFuture = *pFuture.get();
if (__detail::FutureAccessor::IsFailed(refFuture))
{
return {};
}
return __detail::FutureAccessor::GetValue(refFuture);
}
};