Schedule the execution of a coroutine that awaits/yields from Deferreds, wrapping it in a Deferred that will fire on success/failure of the coroutine. If a Deferred is passed to this function, it will be returned directly (mimicing asyncio's ensure_future function).

Coroutine functions return a coroutine object, similar to how generators work. This function turns that coroutine into a Deferred, meaning that it can be used in regular Twisted code. For example:

   import treq
   from twisted.internet.defer import ensureDeferred
   from twisted.internet.task import react

   async def crawl(pages):
       results = {}
       for page in pages:
           results[page] = await treq.content(await treq.get(page))
       return results

   def main(reactor):
       pages = [
       d = ensureDeferred(crawl(pages))
       return d

ParameterscoroThe coroutine object to schedule, or a Deferred. (type: A Python 3.5+ async def coroutine, a Python 3.3+ yield from using types.GeneratorType, or a Deferred.)
Returns (type: Deferred)
API Documentation for Twisted, generated by pydoctor at 2017-06-11 10:59:01.