SocketReader
SocketReader ¶
Reads lines from a connection.
is_reading
property
¶
is_reading: bool
Return whether the reader is currently reading from the connection.
__init__ ¶
__init__(connection: ReadableConnection)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
connection |
ReadableConnection
|
The connection to read lines from. |
required |
start
async
¶
start() -> None
Start reading data from the connection.
Data is read one line at a time. If a SocketReaderDelegate
is set,
the on_message
method is called for every line read.
To stop reading, await the stop
coroutine.
Raises:
Type | Description |
---|---|
ReaderAlreadyStartedError
|
Raised when the reader has already started reading. |
ConnectionClosedError
|
Raised when the connection has closed. |
stop
async
¶
stop() -> None
Stop reading data from the connection.
Sets the internal reading asyncio.Task
as cancelled, and awaits it
until completed. Does nothing if not currently reading.
set_delegate ¶
set_delegate(delegate: SocketReaderDelegate) -> None
Store a weak reference to the delegate
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
delegate |
SocketReaderDelegate
|
The delegate to store. |
required |
SocketReaderDelegate ¶
Bases: Protocol
The delegate of the socket reader.
on_message
abstractmethod
¶
on_message(message: str) -> None
Callback called when the SocketReader
has read a line.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message |
str
|
The read line. |
required |
ReaderAlreadyStartedError ¶
Raised when attempting to start an already started SocketReader
.