Convert a yielded object into a `.Future`. The default implementation accepts lists, dictionaries, and Futures. This has the side effect of starting any coroutines that did not start themselves, similar to `asyncio.ensure_future`. If the `~functools.singledispatch` library is avail
(yielded: _Yieldable)
| 846 | |
| 847 | |
| 848 | def convert_yielded(yielded: _Yieldable) -> Future: |
| 849 | """Convert a yielded object into a `.Future`. |
| 850 | |
| 851 | The default implementation accepts lists, dictionaries, and |
| 852 | Futures. This has the side effect of starting any coroutines that |
| 853 | did not start themselves, similar to `asyncio.ensure_future`. |
| 854 | |
| 855 | If the `~functools.singledispatch` library is available, this function |
| 856 | may be extended to support additional types. For example:: |
| 857 | |
| 858 | @convert_yielded.register(asyncio.Future) |
| 859 | def _(asyncio_future): |
| 860 | return tornado.platform.asyncio.to_tornado_future(asyncio_future) |
| 861 | |
| 862 | .. versionadded:: 4.1 |
| 863 | |
| 864 | """ |
| 865 | if yielded is None or yielded is moment: |
| 866 | return moment |
| 867 | elif yielded is _null_future: |
| 868 | return _null_future |
| 869 | elif isinstance(yielded, (list, dict)): |
| 870 | return multi(yielded) # type: ignore |
| 871 | elif is_future(yielded): |
| 872 | return typing.cast(Future, yielded) |
| 873 | elif isawaitable(yielded): |
| 874 | return _wrap_awaitable(yielded) # type: ignore |
| 875 | else: |
| 876 | raise BadYieldError("yielded unknown object %r" % (yielded,)) |
| 877 | |
| 878 | |
| 879 | convert_yielded = singledispatch(convert_yielded) |
no test coverage detected