mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-26 20:55:35 +03:00
LibCore: Fix compilation of infallible Promise::when_resolved handlers
This overload is currently unused. When used, it doesn't compile due to mismatched return types in the handler provided to the function and the type of `on_resolution`.
This commit is contained in:
parent
75e60d3a68
commit
c190294a76
Notes:
sideshowbarker
2024-07-17 08:13:43 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/c190294a76 Pull-request: https://github.com/SerenityOS/serenity/pull/22519
@ -61,6 +61,26 @@ TEST_CASE(promise_chain_handlers)
|
||||
EXPECT(!rejected);
|
||||
}
|
||||
|
||||
TEST_CASE(infallible_promise_chain_handlers)
|
||||
{
|
||||
Core::EventLoop loop;
|
||||
|
||||
bool resolved = false;
|
||||
bool rejected = false;
|
||||
|
||||
NonnullRefPtr<Core::Promise<int>> promise = MUST(Core::Promise<int>::try_create())
|
||||
->when_resolved([&](int&) { resolved = true; })
|
||||
.when_rejected([&](AK::Error const&) { rejected = true; });
|
||||
|
||||
loop.deferred_invoke([=] {
|
||||
promise->resolve(42);
|
||||
});
|
||||
|
||||
(void)promise->await();
|
||||
EXPECT(resolved);
|
||||
EXPECT(!rejected);
|
||||
}
|
||||
|
||||
TEST_CASE(promise_map)
|
||||
{
|
||||
Core::EventLoop loop;
|
||||
|
@ -82,13 +82,10 @@ public:
|
||||
template<CallableAs<void, Result&> F>
|
||||
Promise& when_resolved(F handler)
|
||||
{
|
||||
on_resolution = [handler = move(handler)](Result& result) { return handler(result); };
|
||||
if (is_resolved()) {
|
||||
auto handler_result = on_resolution(m_result_or_rejection->value());
|
||||
possibly_handle_rejection(handler_result);
|
||||
}
|
||||
|
||||
return *this;
|
||||
return when_resolved([handler = move(handler)](Result& result) -> ErrorOr<void> {
|
||||
handler(result);
|
||||
return {};
|
||||
});
|
||||
}
|
||||
|
||||
template<CallableAs<ErrorOr<void>, Result&> F>
|
||||
|
Loading…
Reference in New Issue
Block a user