Skip to content

Commit

Permalink
refactor: hardcode priority increments for now
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Sep 27, 2024
1 parent 00464c2 commit c12a1cc
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/zwave-js/src/lib/controller/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4689,9 +4689,9 @@ export class ZWaveController
async function* doRebuildRoutes(nodeId: number) {
// Await the process for each node and convert errors to a non-successful result
const result: boolean = yield () =>
// Increase priority by 2, because this call can be nested two levels deep
self.rebuildNodeRoutesInternal(nodeId, 2)
.catch(() => false);
self.rebuildNodeRoutesInternal(nodeId).catch(() =>
false
);

// Track the success in a map
self._rebuildRoutesProgress.set(
Expand Down Expand Up @@ -4856,7 +4856,6 @@ export class ZWaveController

private rebuildNodeRoutesInternal(
nodeId: number,
priorityDelta: number = 0,
): Promise<boolean> {
// Don't start the process twice
const existingTask = this.driver.scheduler.findTask<boolean>((t) =>
Expand All @@ -4866,20 +4865,22 @@ export class ZWaveController

const node = this.nodes.getOrThrow(nodeId);
return this.driver.scheduler.queueTask(
this.getRebuildNodeRoutesTask(node, priorityDelta),
this.getRebuildNodeRoutesTask(node),
);
}

private getRebuildNodeRoutesTask(
node: ZWaveNode,
priorityDelta: number = 0,
): TaskBuilder<boolean> {
let keepAwake: boolean;

const self = this;

return {
priority: TaskPriority.Lower - priorityDelta,
// This task is executed by users and by the network-wide route rebuilding process.
// Since it can possibly be spawned by a "wait for wakeup" task aswell, we need to
// increment the priority by 2 here to avoid blocking.
priority: TaskPriority.Lower - 2,
tag: { id: "rebuild-node-routes", nodeId: node.id },
task: async function* rebuildNodeRoutesTask() {
// Keep battery powered nodes awake during the process
Expand Down

0 comments on commit c12a1cc

Please sign in to comment.