(o)
return o
Converts a coroutine into a Deferred, or returns the object as is if it isn't a coroutine
Converts a coroutine into a Deferred, or returns the object as is if it isn't a coroutine
Converts a coroutine into a Deferred or returns the object as is if it isn t a coroutine
def deferred_from_coro(o) -> Any:
    """Converts a coroutine into a Deferred, or returns the object as is if it isn't a coroutine"""
    if isinstance(o, Deferred):
        return o
    if asyncio.isfuture(o) or inspect.isawaitable(o):
        if not is_asyncio_reactor_installed():
            # wrapping the coroutine directly into a Deferred, this doesn't work correctly with coroutines
            # that use asyncio, e.g. "await asyncio.sleep(1)"
            return ensureDeferred(o)
        else:
            # wrapping the coroutine into a Future and then into a Deferred, this requires AsyncioSelectorReactor
            return Deferred.fromFuture(asyncio.ensure_future(o))
    return o
def deferred_from_coro ( o ) -> Any : if isinstance ( o , Deferred ) : return o if asyncio . isfuture ( o ) or inspect . isawaitable ( o ) : if not is_asyncio_reactor_installed ( ) : # wrapping the coroutine directly into a Deferred, this doesn't work correctly with coroutines # that use asyncio, e.g. "await asyncio.sleep(1)" return ensureDeferred ( o ) else : # wrapping the coroutine into a Future and then into a Deferred, this requires AsyncioSelectorReactor return Deferred . fromFuture ( asyncio . ensure_future ( o ) ) return o