Skip to content

Commit a91400c

Browse files
authored
fix: Correct syntax error when shutdown called before BG service is running (#1940)
1 parent f2f3a85 commit a91400c

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

packages/background-charm-service/src/main.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,16 @@ const service = new BackgroundCharmService({
3939
workerTimeoutMs,
4040
});
4141

42-
const shutdown = () => {
43-
// @ts-ignore: Object is possibly 'undefined'
44-
service.stop().then(() => {
45-
Deno.exit(0);
46-
});
47-
};
42+
function shutdown(service: BackgroundCharmService) {
43+
return () => {
44+
service.stop().then(() => {
45+
Deno.exit(0);
46+
});
47+
};
48+
}
4849

49-
Deno.addSignalListener("SIGINT", shutdown);
50-
Deno.addSignalListener("SIGTERM", shutdown);
50+
Deno.addSignalListener("SIGINT", shutdown(service));
51+
Deno.addSignalListener("SIGTERM", shutdown(service));
5152

5253
service.initialize().then(() => {
5354
console.log("Background Charm Service started successfully");

packages/background-charm-service/src/service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ export class BackgroundCharmService {
5757
this.charmsCell.sink((cs) => this.ensureCharms(cs));
5858
}
5959

60-
stop() {
60+
stop(): Promise<PromiseSettledResult<void>[]> {
6161
// FIXME(ja): stop listening to the charms cell ?
6262
if (!this.isRunning) {
6363
console.log("Service is not running");
64-
return;
64+
return Promise.resolve([]);
6565
}
6666

6767
const promises = Array.from(this.charmSchedulers.values()).map(

0 commit comments

Comments
 (0)