def aiter(x: Union[Iterable[T], AsyncIterable[T]]) -> AsyncIterator[T]:
    """Turns an async iterable or iterable into an async iterator"""
    if hasattr(x, "__anext__"):
        return x  # type: ignore[return-value]
    elif hasattr(x, "__aiter__"):
        return x.__aiter__()

    async def f() -> AsyncIterable[T]:
        ix: Iterable[T] = x
        for item in ix:
            yield item

    return f().__aiter__()
Turns an async iterable or iterable into an async iterator
elasticsearch/_async/helpers.py