summaryrefslogtreecommitdiffstats
path: root/assets
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--assets/js/serialUtil.js24
1 files changed, 19 insertions, 5 deletions
diff --git a/assets/js/serialUtil.js b/assets/js/serialUtil.js
index 8ce3c6e..c4d6d84 100644
--- a/assets/js/serialUtil.js
+++ b/assets/js/serialUtil.js
@@ -21,9 +21,23 @@ async function openPortLineBreak(port, baudRate, outputErrorCallback) {
}
async function closePortLineBreak(port, reader, writer, readableStreamClosed, writerStreamClosed) {
- reader.cancel();
- await readableStreamClosed.catch(() => { /* Ignore the error */ });
- writer.close();
- await writerStreamClosed;
- await port.close();
+ if (reader) {
+ reader.cancel();
+ }
+
+ if (readableStreamClosed) {
+ await readableStreamClosed.catch(() => { /* Ignore the error */ });
+ }
+
+ if (writer) {
+ writer.close();
+ }
+
+ if (writerStreamClosed) {
+ await writerStreamClosed;
+ }
+
+ if (port) {
+ await port.close();
+ }
}