mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-06-19 03:26:39 +00:00
Fix order of inline results not being preserved
This commit is contained in:
parent
628a16f287
commit
f540c4e089
@ -178,11 +178,17 @@ class InlineQuery(EventBuilder):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if results:
|
if results:
|
||||||
results = [self._as_awaitable(x, self._client.loop)
|
futures = [self._as_future(x, self._client.loop)
|
||||||
for x in results]
|
for x in results]
|
||||||
|
|
||||||
done, _ = await asyncio.wait(results, loop=self._client.loop)
|
await asyncio.wait(futures, loop=self._client.loop)
|
||||||
results = [x.result() for x in done]
|
|
||||||
|
# All futures will be in the `done` *set* that `wait` returns.
|
||||||
|
#
|
||||||
|
# Precisely because it's a `set` and not a `list`, it
|
||||||
|
# will not preserve the order, but since all futures
|
||||||
|
# completed we can use our original, ordered `list`.
|
||||||
|
results = [x.result() for x in futures]
|
||||||
else:
|
else:
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
@ -202,9 +208,9 @@ class InlineQuery(EventBuilder):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _as_awaitable(obj, loop):
|
def _as_future(obj, loop):
|
||||||
if inspect.isawaitable(obj):
|
if inspect.isawaitable(obj):
|
||||||
return obj
|
return asyncio.ensure_future(obj, loop=loop)
|
||||||
|
|
||||||
f = loop.create_future()
|
f = loop.create_future()
|
||||||
f.set_result(obj)
|
f.set_result(obj)
|
||||||
|
Loading…
Reference in New Issue
Block a user