advanced generator and context manager