asyncio.py 473 Bytes
Newer Older
1
"""
2
asyncio-related utilities
3 4 5
"""

import asyncio
mathieui's avatar
mathieui committed
6
from functools import wraps
7

8
def future_wrapper(func):
mathieui's avatar
mathieui committed
9
    """
10 11
    Make sure the result of a function call is an asyncio.Future()
    object.
mathieui's avatar
mathieui committed
12 13 14
    """
    @wraps(func)
    def wrapper(*args, **kwargs):
15 16 17 18 19 20
        result = func(*args, **kwargs)
        if isinstance(result, asyncio.Future):
            return result
        future = asyncio.Future()
        future.set_result(result)
        return future
mathieui's avatar
mathieui committed
21 22

    return wrapper