Skip to content
Merged
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
12 changes: 12 additions & 0 deletions packages/background-charm-service/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ export class BackgroundCharmService {
addCancel(scheduler.watch(didCharms));
}

const removedSpaces = new Set(this.charmSchedulers.keys()).difference(dids);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL Set.prototype.difference

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, these functions are convenient. Particularly here, where the natural thing would be to modify the map as you walk through it, which can mess up your iterator.

for (const did of removedSpaces.values()) {
// we are no longer monitoring this space
const scheduler = this.charmSchedulers.get(did);
this.charmSchedulers.delete(did);
// we can't await this in our callback, but we can at least catch and log errors
scheduler?.stop().catch((e) =>
console.error(`Error stopping scheduler: ${e}`)
);
// TODO(@ubik2) I'm not sure if we need to call the cancel function returned by scheduler.watch
}

return cancel;
}
}