diff --git a/giambio/core.py b/giambio/core.py index f6c0756..469d02d 100644 --- a/giambio/core.py +++ b/giambio/core.py @@ -79,6 +79,8 @@ class EventLoop: return task def start(self, coroutine: types.coroutine, *args, **kwargs): + """Starts the eventloop""" + self.spawn(coroutine(*args, **kwargs)) self.loop() @@ -95,6 +97,8 @@ class EventLoop: self.selector.register(sock, EVENT_WRITE, self.running) def wrap_socket(self, sock): + """Wraps a standard socket into an AsyncSocket""" + return AsyncSocket(sock, self) async def read_sock(self, sock: socket.socket, buffer: int): diff --git a/giambio/socket.py b/giambio/socket.py index 1bd9076..52dc821 100644 --- a/giambio/socket.py +++ b/giambio/socket.py @@ -51,3 +51,6 @@ class AsyncSocket(object): def __repr__(self): return f"giambio.socket.AsyncSocket({self.sock}, {self.loop})" + + def __getitem__(self, item): + return self.sock.__getitem__(item) diff --git a/test.py b/test.py index 91b19d8..e7e904c 100644 --- a/test.py +++ b/test.py @@ -21,7 +21,7 @@ async def make_srv(address: tuple): await giambio.sleep(2) logging.info("Done!") while True: - conn, addr = await asock.accept() + conn, addr = await asock.accept() # TODO: Figure out why this I/O operation actually works while other don't logging.info(f"{addr} connected") task = loop.spawn(echo_server(conn, addr)) # await task.cancel() # Cancel task!