1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:27:45 +00:00

LibIMAP: Stop leaking a Core::Promise<bool> in IMAP::Client::connect()

This commit is contained in:
Andreas Kling 2021-09-01 22:56:31 +02:00
parent f4c4b42db9
commit 51ae913bfe
4 changed files with 6 additions and 6 deletions

View file

@ -125,11 +125,11 @@ bool MailWidget::connect_and_login()
m_imap_client = make<IMAP::Client>(server, port, tls); m_imap_client = make<IMAP::Client>(server, port, tls);
auto connection_promise = m_imap_client->connect(); auto connection_promise = m_imap_client->connect();
if (!connection_promise.has_value()) { if (!connection_promise) {
GUI::MessageBox::show_error(window(), String::formatted("Failed to connect to '{}:{}' over {}.", server, port, tls ? "TLS" : "Plaintext")); GUI::MessageBox::show_error(window(), String::formatted("Failed to connect to '{}:{}' over {}.", server, port, tls ? "TLS" : "Plaintext"));
return false; return false;
} }
connection_promise.value()->await(); connection_promise->await();
auto response = m_imap_client->login(username, password)->await().release_value(); auto response = m_imap_client->login(username, password)->await().release_value();

View file

@ -21,7 +21,7 @@ Client::Client(StringView host, unsigned int port, bool start_with_tls)
} }
} }
Optional<RefPtr<Promise<Empty>>> Client::connect() RefPtr<Promise<Empty>> Client::connect()
{ {
bool success; bool success;
if (m_tls) { if (m_tls) {
@ -31,7 +31,7 @@ Optional<RefPtr<Promise<Empty>>> Client::connect()
} }
if (!success) if (!success)
return {}; return {};
m_connect_pending = new Promise<bool> {}; m_connect_pending = Promise<bool>::construct();
return m_connect_pending; return m_connect_pending;
} }

View file

@ -21,7 +21,7 @@ class Client {
public: public:
Client(StringView host, unsigned port, bool start_with_tls); Client(StringView host, unsigned port, bool start_with_tls);
Optional<RefPtr<Promise<Empty>>> connect(); RefPtr<Promise<Empty>> connect();
RefPtr<Promise<Optional<Response>>> send_command(Command&&); RefPtr<Promise<Optional<Response>>> send_command(Command&&);
RefPtr<Promise<Optional<Response>>> send_simple_command(CommandType); RefPtr<Promise<Optional<Response>>> send_simple_command(CommandType);
void send_raw(StringView data); void send_raw(StringView data);

View file

@ -48,7 +48,7 @@ int main(int argc, char** argv)
Core::EventLoop loop; Core::EventLoop loop;
auto client = IMAP::Client(host, port, tls); auto client = IMAP::Client(host, port, tls);
client.connect().value()->await(); client.connect()->await();
auto response = client.login(username, password)->await().release_value(); auto response = client.login(username, password)->await().release_value();
outln("[LOGIN] Login response: {}", response.response_text()); outln("[LOGIN] Login response: {}", response.response_text());