diff --git a/index.html b/index.html index eafec2a..97de903 100644 --- a/index.html +++ b/index.html @@ -949,11 +949,24 @@

} } - const lineReader = port.readable - .pipeThrough(new TextDecoderStream()) + const decoder = new TextDecoderStream(); + const streamClosed = port.readable.pipeTo(decoder.writable); + const lineReader = decoder.readable .pipeThrough(new TransformStream(new LineBreakTransformer())) .getReader(); +

+ As in [[[#close-example]]] the pipe chain cannot be constructed + using only `pipeThrough()`. It is necessary to use `pipeTo()` when + attaching the first {{TransformStream}} to the {{SerialPort}} so + that you can wait for the pipe chain to be closed when you want to + close the port. +

+
+        lineReader.cancel();
+        await streamClosed;
+        await port.close();
+          

Some other ways of encoding message boundaries are to prefix each message with its length or to wait a defined length of time before @@ -1573,7 +1586,7 @@

close() method

-