Fix Connection abstraction leak

This commit is contained in:
Lonami Exo
2019-02-21 10:41:33 +01:00
parent 96270bdc18
commit 6de7329ce7
5 changed files with 19 additions and 13 deletions

View File

@@ -76,6 +76,9 @@ class Connection(abc.ABC):
await asyncio.open_connection(sock=s, loop=self._loop)
self._connected = True
self._init_conn()
await self._writer.drain()
self._send_task = self._loop.create_task(self._send_loop())
self._recv_task = self._loop.create_task(self._recv_loop())
@@ -170,6 +173,18 @@ class Connection(abc.ABC):
except asyncio.CancelledError:
break
@abc.abstractmethod
def _init_conn(self):
"""
This method will be called after `connect` is called.
After this method finishes, the writer will be drained.
Subclasses should make use of this if they need to send
data to Telegram to indicate which connection mode will
be used.
"""
raise NotImplemented
@abc.abstractmethod
def _send(self, data):
"""