Skip to content

Commit

Permalink
fix: re-queue current transaction in correct queue
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Nov 20, 2023
1 parent 825abaf commit 11bab87
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions packages/zwave-js/src/lib/driver/Driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3614,7 +3614,9 @@ export class Driver extends TypedEventEmitter<DriverEventCallbacks>
// Re-queue the transaction, so it can get handled next.
// Its message generator may have finished, so reset that too.
transaction.reset();
this.queue.add(transaction.clone());
this.getQueueForTransaction(transaction).add(
transaction.clone(),
);

this._controller?.setStatus(ControllerStatus.Ready);
this._recoveryPhase = ControllerRecoveryPhase.None;
Expand Down Expand Up @@ -3730,7 +3732,9 @@ export class Driver extends TypedEventEmitter<DriverEventCallbacks>
// Re-queue the transaction, so it can get handled next.
// Its message generator may have finished, so reset that too.
transaction.reset();
this.queue.add(transaction.clone());
this.getQueueForTransaction(transaction).add(
transaction.clone(),
);

this._controller?.setStatus(ControllerStatus.Ready);
this._recoveryPhase =
Expand Down Expand Up @@ -5158,6 +5162,17 @@ ${handlers.length} left`,
return result;
}

private getQueueForTransaction(t: Transaction): TransactionQueue {
if (
t.priority === MessagePriority.Immediate
|| t.priority === MessagePriority.ControllerImmediate
) {
return this.immediateQueue;
} else {
return this.queue;
}
}

/**
* Sends a message to the Z-Wave stick.
* @param msg The message to send
Expand Down Expand Up @@ -5267,14 +5282,7 @@ ${handlers.length} left`,
transaction.tag = options.tag;

// And queue it
if (
transaction.priority === MessagePriority.Immediate
|| transaction.priority === MessagePriority.ControllerImmediate
) {
this.immediateQueue.add(transaction);
} else {
this.queue.add(transaction);
}
this.getQueueForTransaction(transaction).add(transaction);
transaction.setProgress({ state: TransactionState.Queued });

// If the transaction should expire, start the timeout
Expand Down

0 comments on commit 11bab87

Please sign in to comment.