def test_mapper_generator_shutdown(create_mapper, loop):
    """
    Check that throwing an exception into AsyncMapper.iterate() terminates it cleanly.
    Note that finalising a generator involves throwing StopIteration into it.
    """

    async def process(row):
        await mapper.to_thread(functools.partial(sync, loop, fake_io, row))
        return row

    class MyError(Exception):
        pass

    mapper = create_mapper(process, range(50), workers=10, loop=loop)
    iterator = mapper.iterate(timeout=4)
    next(iterator)
    with pytest.raises(MyError):
        iterator.throw(MyError)

    Check that throwing an exception into AsyncMapper.iterate() terminates it cleanly.
    Note that finalising a generator involves throwing StopIteration into it.
    
tests/unit/test_asyn.py