Wraps a synchronous function into an asynchronous function.

def wrap_sync(func):
    """Wraps a synchronous function into an asynchronous function."""
    @functools.wraps(func)
    def wrapped(*args, **kwargs):
        fut = asyncio.Future()
        def green():
            try:
                fut.set_result(func(*args, **kwargs))
            except BaseException as e:
                fut.set_exception(e)
        greenlet.greenlet(green).switch()
        return fut
    return wrapped