mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 18:20:43 +09:00
LibCore+Userland: Allow canceling promises
To make EventLoop cancel its managed Promises, we need the ability to cancel them in the first place.
This commit is contained in:
parent
afd0f941b7
commit
bfd9f681f7
Notes:
sideshowbarker
2024-07-16 23:34:49 +09:00
Author: https://github.com/kleinesfilmroellchen
Commit: bfd9f681f7
Pull-request: https://github.com/SerenityOS/serenity/pull/16715
Issue: https://github.com/SerenityOS/serenity/issues/14945
Reviewed-by: https://github.com/ADKaster
Reviewed-by: https://github.com/BenWiederhake
6 changed files with 48 additions and 35 deletions
|
@ -44,20 +44,20 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
Core::EventLoop loop;
|
||||
auto client = TRY(tls ? IMAP::Client::connect_tls(host, port) : IMAP::Client::connect_plaintext(host, port));
|
||||
client->connection_promise()->await();
|
||||
TRY(client->connection_promise()->await());
|
||||
|
||||
auto response = client->login(username, password.view())->await().release_value();
|
||||
auto response = TRY(client->login(username, password.view())->await()).release_value();
|
||||
outln("[LOGIN] Login response: {}", response.response_text());
|
||||
|
||||
response = move(client->send_simple_command(IMAP::CommandType::Capability)->await().value().get<IMAP::SolidResponse>());
|
||||
response = move(TRY(client->send_simple_command(IMAP::CommandType::Capability)->await()).value().get<IMAP::SolidResponse>());
|
||||
outln("[CAPABILITY] First capability: {}", response.data().capabilities().first());
|
||||
bool idle_supported = !response.data().capabilities().find_if([](auto capability) { return capability.equals_ignoring_ascii_case("IDLE"sv); }).is_end();
|
||||
|
||||
response = client->list(""sv, "*"sv)->await().release_value();
|
||||
response = TRY(client->list(""sv, "*"sv)->await()).release_value();
|
||||
outln("[LIST] First mailbox: {}", response.data().list_items().first().name);
|
||||
|
||||
auto mailbox = "Inbox"sv;
|
||||
response = client->select(mailbox)->await().release_value();
|
||||
response = TRY(client->select(mailbox)->await()).release_value();
|
||||
outln("[SELECT] Select response: {}", response.response_text());
|
||||
|
||||
auto message = Message {
|
||||
|
@ -71,7 +71,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
"So, \"Hello\"."
|
||||
};
|
||||
auto promise = client->append("INBOX"sv, move(message));
|
||||
response = promise->await().release_value();
|
||||
response = TRY(promise->await()).release_value();
|
||||
outln("[APPEND] Response: {}", response.response_text());
|
||||
|
||||
Vector<IMAP::SearchKey> keys;
|
||||
|
@ -79,13 +79,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
IMAP::SearchKey::From { "jdoe@machine.example" } });
|
||||
keys.append(IMAP::SearchKey {
|
||||
IMAP::SearchKey::Subject { "Saying Hello" } });
|
||||
response = client->search({}, move(keys), false)->await().release_value();
|
||||
response = TRY(client->search({}, move(keys), false)->await()).release_value();
|
||||
|
||||
Vector<unsigned> search_results = move(response.data().search_results());
|
||||
auto added_message = search_results.first();
|
||||
outln("[SEARCH] Number of results: {}", search_results.size());
|
||||
|
||||
response = client->status("INBOX"sv, { IMAP::StatusItemType::Recent, IMAP::StatusItemType::Messages })->await().release_value();
|
||||
response = TRY(client->status("INBOX"sv, { IMAP::StatusItemType::Recent, IMAP::StatusItemType::Messages })->await()).release_value();
|
||||
outln("[STATUS] Recent items: {}", response.data().status_item().get(IMAP::StatusItemType::Recent));
|
||||
|
||||
for (auto item : search_results) {
|
||||
|
@ -118,7 +118,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
};
|
||||
// clang-format on
|
||||
|
||||
auto fetch_response = client->fetch(fetch_command, false)->await().release_value();
|
||||
auto fetch_response = TRY(client->fetch(fetch_command, false)->await()).release_value();
|
||||
outln("[FETCH] Subject of search result: {}",
|
||||
fetch_response.data()
|
||||
.fetch_data()
|
||||
|
@ -136,22 +136,22 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
// FIXME: There is a discrepancy between IMAP::Sequence wanting signed ints
|
||||
// and IMAP search results returning unsigned ones. Find which one is
|
||||
// more correct and fix this.
|
||||
response = client->store(IMAP::StoreMethod::Add, { static_cast<int>(added_message), static_cast<int>(added_message) }, false, { "\\Deleted" }, false)->await().release_value();
|
||||
response = TRY(client->store(IMAP::StoreMethod::Add, { static_cast<int>(added_message), static_cast<int>(added_message) }, false, { "\\Deleted" }, false)->await()).release_value();
|
||||
outln("[STORE] Store response: {}", response.response_text());
|
||||
|
||||
response = move(client->send_simple_command(IMAP::CommandType::Expunge)->await().release_value().get<IMAP::SolidResponse>());
|
||||
response = move(TRY(client->send_simple_command(IMAP::CommandType::Expunge)->await()).release_value().get<IMAP::SolidResponse>());
|
||||
outln("[EXPUNGE] Number of expunged entries: {}", response.data().expunged().size());
|
||||
|
||||
if (idle_supported) {
|
||||
VERIFY(client->idle()->await().has_value());
|
||||
VERIFY(TRY(client->idle()->await()).has_value());
|
||||
sleep(3);
|
||||
response = client->finish_idle()->await().release_value();
|
||||
response = TRY(client->finish_idle()->await()).release_value();
|
||||
outln("[IDLE] Idle response: {}", response.response_text());
|
||||
} else {
|
||||
outln("[IDLE] Skipped. No IDLE support.");
|
||||
}
|
||||
|
||||
response = move(client->send_simple_command(IMAP::CommandType::Logout)->await().release_value().get<IMAP::SolidResponse>());
|
||||
response = move(TRY(client->send_simple_command(IMAP::CommandType::Logout)->await()).release_value().get<IMAP::SolidResponse>());
|
||||
outln("[LOGOUT] Bye: {}", response.data().bye_message().value());
|
||||
|
||||
client->close();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue