diff options
author | Ernesto Castellotti <mail@ernestocastellotti.it> | 2023-01-11 19:22:18 +0100 |
---|---|---|
committer | Simone <26844016+simonebortolin@users.noreply.github.com> | 2023-01-12 00:02:02 +0100 |
commit | 16e7e7d04765ffdb07a491f1f3b1607006707130 (patch) | |
tree | eb48c4c1b79486b570b09c5a62cdbac2b9d0379f | |
parent | Add sfpModel parameter and remove successCallback (diff) | |
download | hack-gpon.github.io-16e7e7d04765ffdb07a491f1f3b1607006707130.tar hack-gpon.github.io-16e7e7d04765ffdb07a491f1f3b1607006707130.tar.gz hack-gpon.github.io-16e7e7d04765ffdb07a491f1f3b1607006707130.tar.bz2 hack-gpon.github.io-16e7e7d04765ffdb07a491f1f3b1607006707130.tar.lz hack-gpon.github.io-16e7e7d04765ffdb07a491f1f3b1607006707130.tar.xz hack-gpon.github.io-16e7e7d04765ffdb07a491f1f3b1607006707130.tar.zst hack-gpon.github.io-16e7e7d04765ffdb07a491f1f3b1607006707130.zip |
-rw-r--r-- | assets/js/serialUtil.js | 24 |
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(); + } } |