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)
| 870 | |
| 871 | |
| 872 | def convert_yielded(yielded: _Yieldable) -> Future: |
| 873 | """Convert a yielded object into a `.Future`. |
| 874 | |
| 875 | The default implementation accepts lists, dictionaries, and |
| 876 | Futures. This has the side effect of starting any coroutines that |
| 877 | did not start themselves, similar to `asyncio.ensure_future`. |
| 878 | |
| 879 | If the `~functools.singledispatch` library is available, this function |
| 880 | may be extended to support additional types. For example:: |
| 881 | |
| 882 | @convert_yielded.register(asyncio.Future) |
| 883 | def _(asyncio_future): |
| 884 | return tornado.platform.asyncio.to_tornado_future(asyncio_future) |
| 885 | |
| 886 | .. versionadded:: 4.1 |
| 887 | |
| 888 | """ |
| 889 | if yielded is None or yielded is moment: |
| 890 | return moment |
| 891 | elif yielded is _null_future: |
| 892 | return _null_future |
| 893 | elif isinstance(yielded, (list, dict)): |
| 894 | return multi(yielded) # type: ignore |
| 895 | elif is_future(yielded): |
| 896 | return typing.cast(Future, yielded) |
| 897 | elif isawaitable(yielded): |
| 898 | return _wrap_awaitable(yielded) # type: ignore |
| 899 | else: |
| 900 | raise BadYieldError(f"yielded unknown object {yielded!r}") |
| 901 | |
| 902 | |
| 903 | convert_yielded = singledispatch(convert_yielded) |
no test coverage detected