Move chan connect helper to ipc mod

asyncgen_closing_fix
Tyler Goodlet 2018-07-11 18:08:57 -04:00
parent bb9309bdf5
commit 25852794a8
1 changed files with 12 additions and 0 deletions

View File

@ -5,6 +5,7 @@ from typing import Coroutine, Tuple
import msgpack
import trio
from async_generator import asynccontextmanager
from .log import get_logger
log = get_logger('ipc')
@ -189,3 +190,14 @@ class Channel:
def connected(self):
return self.squeue.connected() if self.squeue else False
@asynccontextmanager
async def _connect_chan(host, port):
"""Create and connect a channel with disconnect on
context manager teardown.
"""
chan = Channel((host, port))
await chan.connect()
yield chan
await chan.aclose()