asyncio_serial: add force option to set_read_callback

If force == true and None is passed as the read callback then
the existing reader will be closed and a new reader is created.
This can be used to exit an existing reader's iterator without
closing the serial connection.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan committed 2025-09-22 15:10:57 -04:00
1 parent 596e7d9e79
commit 72ca7dbe05
1 file changed
+4 -2
+4 -2
View File
@@ -55,9 +55,11 @@ class AsyncSerialConnection:
server = config.get_server()
return AsyncSerialConnection(server, name, port, baud)
def set_read_callback(self, callback: Callable[[bytes], None] | None) -> None:
def set_read_callback(
self, callback: Callable[[bytes], None] | None, force: bool = False
) -> None:
if callback is None:
if self.reader_active:
if not force and self.reader_active:
return
self._reader.feed_eof()
self._reader = asyncio.StreamReader(limit=READER_LIMIT)