Skip to content

Commit

Permalink
Fix interrupts of commands
Browse files Browse the repository at this point in the history
Signed-off-by: paulober <[email protected]>
  • Loading branch information
paulober committed Aug 30, 2024
1 parent 2ba6730 commit 717dcd9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/serialHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const BUFFER_R01 = Buffer.from("R\x01");
const BUFFER_01 = Buffer.from("\x01");
const BUFFER_03 = Buffer.from("\x03");
const BUFFER_04 = Buffer.from("\x04");
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const BUFFER_CR = Buffer.from("\r");
const BUFFER_TAB = Buffer.from("\t");

Expand Down Expand Up @@ -515,7 +514,10 @@ export async function executeCommandWithResult(
// call exe without result and then call follow
await executeCommandWithoutResult(port, command);

return follow(port, timeout, receiver);
// needs to be awaited here, otherwise it will
// return the promisse which will run the final block
// of this try catch as the promisse is awaited somewhere else
return await follow(port, timeout, receiver);
} catch {
if (interrupted) {
return { data: "", error: "Interrupted" };
Expand Down
4 changes: 4 additions & 0 deletions src/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ async function handleCommand(command: string): Promise<void> {
if (open) {
relayInput = true;
rl.resume();
// for testing of interrupts
setTimeout(() => {
serialCom.interruptExecution();
}, 5000);
}
},
(data: Buffer) => {
Expand Down

0 comments on commit 717dcd9

Please sign in to comment.