Skip to content

Commit

Permalink
Refactor to async/await
Browse files Browse the repository at this point in the history
  • Loading branch information
Maaaartin committed Feb 21, 2024
1 parent 2b9d298 commit 85ce384
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,17 @@ export class Client {
/**
* Kills the adb server.
*/
public kill(): Promise<void> {
// 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<void> {
try {
await new KillCommand(await this.connection()).execute();
} catch (error) {
if (
!(error instanceof Error) ||
(error as NodeJS.ErrnoException).code !== 'ECONNREFUSED'
) {
throw error;
}
}
}

/**
Expand Down

0 comments on commit 85ce384

Please sign in to comment.