Kaynağa Gözat

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

Andreas Kling 3 yıl önce
ebeveyn
işleme
51ae913bfe

+ 2 - 2
Userland/Applications/Mail/MailWidget.cpp

@@ -125,11 +125,11 @@ bool MailWidget::connect_and_login()
 
     m_imap_client = make<IMAP::Client>(server, port, tls);
     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"));
         return false;
     }
-    connection_promise.value()->await();
+    connection_promise->await();
 
     auto response = m_imap_client->login(username, password)->await().release_value();
 

+ 2 - 2
Userland/Libraries/LibIMAP/Client.cpp

@@ -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;
     if (m_tls) {
@@ -31,7 +31,7 @@ Optional<RefPtr<Promise<Empty>>> Client::connect()
     }
     if (!success)
         return {};
-    m_connect_pending = new Promise<bool> {};
+    m_connect_pending = Promise<bool>::construct();
     return m_connect_pending;
 }
 

+ 1 - 1
Userland/Libraries/LibIMAP/Client.h

@@ -21,7 +21,7 @@ class Client {
 public:
     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_simple_command(CommandType);
     void send_raw(StringView data);

+ 1 - 1
Userland/Utilities/test-imap.cpp

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