import functools


def _asyncable(func):
    """Wrap a function, so that async=True will run it in a thread."""
    @functools.wraps(func)
    def _wrapped(self, *args, **kwargs):
        if kwargs.pop('async', False):
            return self._submit_concurrent(func, self, *args, **kwargs)
        else:
            return func(self, *args, **kwargs)
    return _wrapped