def chain_return_value(future, loop, return_value):
    """Compatible way to return a value in all Pythons.

    PEP 479, raise StopIteration(value) from a coroutine won't work forever,
    but "return value" doesn't work in Python 2. Instead, Motor methods that
    return values resolve a Future with it, and are implemented with callbacks
    rather than a coroutine internally.
    """
    chained = asyncio.Future(loop=loop)

    def copy(_future):
        if _future.exception() is not None:
            chained.set_exception(_future.exception())
        else:
            chained.set_result(return_value)

    future._future.add_done_callback(functools.partial(loop.add_callback, copy))
    return chained
def chain_return_value ( future , loop , return_value ) : chained = asyncio . Future ( loop = loop ) def copy ( _future ) : if _future . exception ( ) is not None : chained . set_exception ( _future . exception ( ) ) else : chained . set_result ( return_value ) future . _future . add_done_callback ( functools . partial ( loop . add_callback , copy ) ) return chained
Compatible way to return a value in all Pythons.

    PEP 479, raise StopIteration(value) from a coroutine won't work forever,
    but "return value" doesn't work in Python 2. Instead, Motor methods that
    return values resolve a Future with it, and are implemented with callbacks
    rather than a coroutine internally.