# Path: aredis/exceptions.py
# class ConnectionError(RedisError):
#     pass
# 
# Path: aredis/utils.py
# def b(x):
#     return x.encode('latin-1') if not isinstance(x, bytes) else x
# 
# Path: tests/client/conftest.py
# def skip_if_server_version_lt(min_version):
#     loop = asyncio.get_event_loop()
#     version = StrictVersion(loop.run_until_complete(get_version()))
#     check = version < StrictVersion(min_version)
#     return pytest.mark.skipif(check, reason="")


import asyncio
import pickle
import time
import pytest
import aredis
from aredis.exceptions import ConnectionError
from aredis.utils import b
from .conftest import skip_if_server_version_lt
from __future__ import with_statement





async def wait_for_message(pubsub, timeout=0.5, ignore_subscribe_messages=False):
    now = time.time()
    timeout = now + timeout
    while now < timeout:
        message = await pubsub.get_message(
            ignore_subscribe_messages=ignore_subscribe_messages,
            timeout=0.01
        )
        if message is not None:
            return message
        await asyncio.sleep(0.01)
        now = time.time()

# Path: aredis/exceptions.py
# class ConnectionError(RedisError):
#     pass
# 
# Path: aredis/utils.py
# def b(x):
#     return x.encode('latin-1') if not isinstance(x, bytes) else x
# 
# Path: tests/client/conftest.py
# def skip_if_server_version_lt(min_version):
#     loop = asyncio.get_event_loop()
#     version = StrictVersion(loop.run_until_complete(get_version()))
#     check = version < StrictVersion(min_version)
#     return pytest.mark.skipif(check, reason="")


# Path: tests/client/test_pubsub.py
import asyncio
import pickle
import time
import pytest
import aredis
from aredis.exceptions import ConnectionError
from aredis.utils import b
from .conftest import skip_if_server_version_lt

from __future__ import with_statement





async def wait_for_message(pubsub, timeout=0.5, ignore_subscribe_messages=False):
    now = time.time()
    timeout = now + timeout
    while now < timeout:
        message = await pubsub.get_message(
            ignore_subscribe_messages=ignore_subscribe_messages,
            timeout=0.01
        )
        if message is not None:
            return message
        await asyncio.sleep(0.01)
        now = time.time()

    return None