Skip to content

Commit

Permalink
Add static shutdown() method to ApitallyClient
Browse files Browse the repository at this point in the history
  • Loading branch information
itssimon committed Nov 24, 2023
1 parent a98155f commit fdc2711
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
18 changes: 12 additions & 6 deletions src/common/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ export class ApitallyClient {
return ApitallyClient.instance;
}

public static async shutdown() {
if (ApitallyClient.instance) {
await ApitallyClient.instance.handleShutdown();
}
}

public async handleShutdown() {
this.stopSync();
await this.sendRequestsData();
ApitallyClient.instance = undefined;
}

private getHubUrl() {
const baseURL =
process.env.APITALLY_HUB_BASE_URL || "https://hub.apitally.io";
Expand Down Expand Up @@ -146,12 +158,6 @@ export class ApitallyClient {
}
}

public async handleShutdown() {
this.stopSync();
await this.sendRequestsData();
ApitallyClient.instance = undefined;
}

public setAppInfo(appInfo: AppInfo) {
this.appInfo = appInfo;
this.appInfoSent = false;
Expand Down
4 changes: 1 addition & 3 deletions tests/common/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ describe("Client", () => {
});

afterEach(async () => {
try {
await ApitallyClient.getInstance().handleShutdown();
} catch (error) {} // eslint-disable-line no-empty
await ApitallyClient.shutdown();
});
});

0 comments on commit fdc2711

Please sign in to comment.