Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions packages/background-charm-service/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@ const service = new BackgroundCharmService({
workerTimeoutMs,
});

const shutdown = () => {
// @ts-ignore: Object is possibly 'undefined'
service.stop().then(() => {
Deno.exit(0);
});
};
function shutdown(service: BackgroundCharmService) {
return () => {
service.stop().then(() => {
Deno.exit(0);
});
};
}

Deno.addSignalListener("SIGINT", shutdown);
Deno.addSignalListener("SIGTERM", shutdown);
Deno.addSignalListener("SIGINT", shutdown(service));
Deno.addSignalListener("SIGTERM", shutdown(service));

service.initialize().then(() => {
console.log("Background Charm Service started successfully");
Expand Down
4 changes: 2 additions & 2 deletions packages/background-charm-service/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ export class BackgroundCharmService {
this.charmsCell.sink((cs) => this.ensureCharms(cs));
}

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

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