Example #1
0
File: app.py Project: rheehot/mario
async def program_runner(
    traversals: List[interfaces.Traversal],
    items: AsyncIterable,
    context: interfaces.Context,
):
    async with async_exit_stack.AsyncExitStack() as stack:
        for traversal in traversals:
            items = await call_traversal(context, traversal, items, stack)

        return stack.pop_all(), items
Example #2
0
    async def _run_async_server(self, raw_socket):
        socket = anyio._get_asynclib().Socket(raw_socket)

        # TODO: resource usage warning
        async with async_exit_stack.AsyncExitStack() as stack:
            tcp_server = await stack.enter_async_context(
                anyio._networking.SocketStreamServer(socket, None, False, False))
            task_group = await stack.enter_async_context(anyio.create_task_group())

            services_dict = {}
            for key, value in self.services.items():
                services_dict[key] = await stack.enter_async_context(value)

            async for socket in tcp_server.accept_connections():
                await task_group.spawn(ConnectionHandler(services_dict), socket)