mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:17:44 +00:00
LibCore: Slightly rework the Core::Promise API
The previous iteration of this API was somewhat odd and rough in random places, which degraded usability and made less than perfect sense. This commit reworks the API to be a little closer to more conventional promise APIs (a la javascript promises). Also adds a test to ensure the class even works.
This commit is contained in:
parent
5a0ad6812c
commit
0c5c75e8a4
9 changed files with 150 additions and 38 deletions
|
@ -64,7 +64,7 @@ ErrorOr<void> Client::on_ready_to_receive()
|
|||
|
||||
// Once we get server hello we can start sending.
|
||||
if (m_connect_pending) {
|
||||
TRY(m_connect_pending->resolve({}));
|
||||
m_connect_pending->resolve({});
|
||||
m_connect_pending.clear();
|
||||
m_buffer.clear();
|
||||
return {};
|
||||
|
@ -227,13 +227,13 @@ ErrorOr<void> Client::handle_parsed_response(ParseStatus&& parse_status)
|
|||
bool should_send_next = false;
|
||||
if (!parse_status.successful) {
|
||||
m_expecting_response = false;
|
||||
TRY(m_pending_promises.first()->resolve({}));
|
||||
m_pending_promises.first()->resolve({});
|
||||
m_pending_promises.remove(0);
|
||||
}
|
||||
if (parse_status.response.has_value()) {
|
||||
m_expecting_response = false;
|
||||
should_send_next = parse_status.response->has<SolidResponse>();
|
||||
TRY(m_pending_promises.first()->resolve(move(parse_status.response)));
|
||||
m_pending_promises.first()->resolve(move(parse_status.response));
|
||||
m_pending_promises.remove(0);
|
||||
}
|
||||
|
||||
|
@ -386,7 +386,7 @@ RefPtr<Promise<Optional<SolidResponse>>> Client::append(StringView mailbox, Mess
|
|||
auto response_promise = Promise<Optional<Response>>::construct();
|
||||
m_pending_promises.append(response_promise);
|
||||
|
||||
continue_req->on_resolved = [this, message2 { move(message) }](auto& data) -> ErrorOr<void> {
|
||||
continue_req->on_resolution = [this, message2 { move(message) }](auto& data) -> ErrorOr<void> {
|
||||
if (!data.has_value()) {
|
||||
TRY(handle_parsed_response({ .successful = false, .response = {} }));
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue