From 85ce384b0f40756f9fda97cc800548021e3b121f Mon Sep 17 00:00:00 2001 From: Martin Svoboda Date: Wed, 21 Feb 2024 13:14:37 +0100 Subject: [PATCH] Refactor to async/await --- src/client.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/client.ts b/src/client.ts index fd7a5acd..e2039ed6 100644 --- a/src/client.ts +++ b/src/client.ts @@ -243,15 +243,17 @@ export class Client { /** * Kills the adb server. */ - public kill(): Promise { - // TODO try catch - return this.connection() - .catch((error) => { - if (error.code !== 'ECONNREFUSED') { - throw error; - } - }) - .then((conn) => conn && new KillCommand(conn).execute()); + public async kill(): Promise { + try { + await new KillCommand(await this.connection()).execute(); + } catch (error) { + if ( + !(error instanceof Error) || + (error as NodeJS.ErrnoException).code !== 'ECONNREFUSED' + ) { + throw error; + } + } } /**