1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 18:57:35 +00:00

LibCore: Move the Promise::await() result instead of returning a ref

Returning a reference resulted in Mail's use of Promise causing a crash.
Also, awaiting an already-awaited promise is an odd thing to do anyway,
so let's just make it release the resolved/rejected value instead of
returning a reference to it.

Co-Authored-By: Valtteri Koskivuori <vkoskiv@gmail.com>
This commit is contained in:
Ali Mohammad Pur 2023-07-24 01:41:18 +03:30 committed by Ali Mohammad Pur
parent 8ed3cc5f7b
commit 9f4feb7315
2 changed files with 5 additions and 5 deletions

View file

@ -50,12 +50,12 @@ public:
return m_result_or_rejection.has_value() && !m_result_or_rejection->is_error();
}
ErrorOr<Result, ErrorType>& await()
ErrorOr<Result, ErrorType> await()
{
while (!m_result_or_rejection.has_value())
Core::EventLoop::current().pump();
return *m_result_or_rejection;
return m_result_or_rejection.release_value();
}
// Converts a Promise<A> to a Promise<B> using a function func: A -> B