return Future from async send() to *optionally* wait for it to hit the wire

This commit is contained in:
jesopo 2020-04-05 13:17:53 +01:00
parent e470d57780
commit 2a9d658207

View file

@ -34,12 +34,13 @@ class Server(IServer):
self._read_queue: Queue[Tuple[Line, List[Emit]]] = Queue() self._read_queue: Queue[Tuple[Line, List[Emit]]] = Queue()
self.desired_caps: Set[ICapability] = set([]) self.desired_caps: Set[ICapability] = set([])
async def send_raw(self, line: str, priority=SendPriority.DEFAULT): async def send_raw(self, line: str, priority=SendPriority.DEFAULT
await self.send(tokenise(line), priority) ) -> Future:
async def send(self, line: Line, priority=SendPriority.DEFAULT): return await self.send(tokenise(line), priority)
async def send(self, line: Line, priority=SendPriority.DEFAULT) -> Future:
prio_line = SentLine(priority, line) prio_line = SentLine(priority, line)
await self._write_queue.put(prio_line) await self._write_queue.put(prio_line)
await prio_line.future prio_line.future
def set_throttle(self, rate: int, time: float): def set_throttle(self, rate: int, time: float):
self.throttle.rate_limit = rate self.throttle.rate_limit = rate