don't catch and "handle" server disconnect. throw up to bot.py
This commit is contained in:
parent
feb71d5b14
commit
3208ee738c
2 changed files with 13 additions and 15 deletions
|
@ -1,8 +1,9 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import anyio
|
import anyio
|
||||||
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from ircstates.server import ServerDisconnectedException
|
||||||
|
|
||||||
from .server import ConnectionParams, Server
|
from .server import ConnectionParams, Server
|
||||||
from .transport import TCPTransport
|
from .transport import TCPTransport
|
||||||
from .interface import IBot, IServer
|
from .interface import IBot, IServer
|
||||||
|
@ -39,8 +40,9 @@ class Bot(IBot):
|
||||||
async with anyio.create_task_group() as tg:
|
async with anyio.create_task_group() as tg:
|
||||||
async def _read():
|
async def _read():
|
||||||
while not tg.cancel_scope.cancel_called:
|
while not tg.cancel_scope.cancel_called:
|
||||||
both = await server.next_line()
|
try:
|
||||||
if both is None:
|
both = await server.next_line()
|
||||||
|
except ServerDisconnectedException:
|
||||||
break
|
break
|
||||||
await tg.cancel_scope.cancel()
|
await tg.cancel_scope.cancel()
|
||||||
|
|
||||||
|
|
|
@ -140,7 +140,7 @@ class Server(IServer):
|
||||||
if line.command == "PING":
|
if line.command == "PING":
|
||||||
await self.send(build("PONG", line.params))
|
await self.send(build("PONG", line.params))
|
||||||
|
|
||||||
async def next_line(self) -> Optional[Tuple[Line, List[Emit]]]:
|
async def next_line(self) -> Tuple[Line, List[Emit]]:
|
||||||
if self._read_queue:
|
if self._read_queue:
|
||||||
both = self._read_queue.popleft()
|
both = self._read_queue.popleft()
|
||||||
else:
|
else:
|
||||||
|
@ -150,7 +150,7 @@ class Server(IServer):
|
||||||
lines = self.recv(data)
|
lines = self.recv(data)
|
||||||
except ServerDisconnectedException:
|
except ServerDisconnectedException:
|
||||||
self.disconnected = True
|
self.disconnected = True
|
||||||
return None
|
raise
|
||||||
|
|
||||||
if lines:
|
if lines:
|
||||||
self._read_queue.extend(lines[1:])
|
self._read_queue.extend(lines[1:])
|
||||||
|
@ -170,17 +170,13 @@ class Server(IServer):
|
||||||
self._wait_for.append((our_fut, response))
|
self._wait_for.append((our_fut, response))
|
||||||
while self._wait_for:
|
while self._wait_for:
|
||||||
both = await self.next_line()
|
both = await self.next_line()
|
||||||
|
line, emits = both
|
||||||
|
|
||||||
if not both is None:
|
for i, (fut, waiting) in enumerate(self._wait_for):
|
||||||
line, emits = both
|
if waiting.match(self, line):
|
||||||
|
fut.set_result(line)
|
||||||
for i, (fut, waiting) in enumerate(self._wait_for):
|
self._wait_for.pop(i)
|
||||||
if waiting.match(self, line):
|
break
|
||||||
fut.set_result(line)
|
|
||||||
self._wait_for.pop(i)
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
fut.set_result(build(""))
|
|
||||||
|
|
||||||
return await our_fut
|
return await our_fut
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue