async def smap ( source , func , * more_sources ) : if more_sources : source = zip ( source , * more_sources ) async with streamcontext ( source ) as streamer : async for item in streamer : yield func ( * item ) if more_sources else func ( item )
python async map multiple args
Apply a given function to the elements of one or several asynchronous sequences .
async def smap(source, func, *more_sources):
    """Apply a given function to the elements of one or several
    asynchronous sequences.

    Each element is used as a positional argument, using the same order as
    their respective sources. The generation continues until the shortest
    sequence is exhausted. The function is treated synchronously.

    Note: if more than one sequence is provided, they're awaited concurrently
    so that their waiting times don't add up.
    """
    if more_sources:
        source = zip(source, *more_sources)
    async with streamcontext(source) as streamer:
        async for item in streamer:
            yield func(*item) if more_sources else func(item)