mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-20 16:00:29 +00:00
Add compatibility shim for asyncio.Future creation.
Should provide better support for uvloop.
This commit is contained in:
parent
62f43889c0
commit
b876133e87
@ -678,7 +678,7 @@ class Client:
|
||||
|
||||
return result
|
||||
|
||||
future = asyncio.Future(loop=self.loop)
|
||||
future = compat.create_future(self.loop)
|
||||
self._listeners.append((predicate, future, WaitForType.message))
|
||||
try:
|
||||
message = yield from asyncio.wait_for(future, timeout, loop=self.loop)
|
||||
@ -788,7 +788,7 @@ class Client:
|
||||
|
||||
return result
|
||||
|
||||
future = asyncio.Future(loop=self.loop)
|
||||
future = compat.create_future(self.loop)
|
||||
self._listeners.append((predicate, future, WaitForType.reaction))
|
||||
try:
|
||||
return (yield from asyncio.wait_for(future, timeout, loop=self.loop))
|
||||
|
@ -31,6 +31,15 @@ try:
|
||||
except AttributeError:
|
||||
create_task = asyncio.async
|
||||
|
||||
try:
|
||||
_create_future = asyncio.AbstractEventLoop.create_future
|
||||
except AttributeError:
|
||||
def create_future(loop):
|
||||
return asyncio.Future(loop=loop)
|
||||
else:
|
||||
def create_future(loop):
|
||||
return loop.create_future()
|
||||
|
||||
try:
|
||||
run_coroutine_threadsafe = asyncio.run_coroutine_threadsafe
|
||||
except AttributeError:
|
||||
|
@ -234,7 +234,7 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol):
|
||||
A future to wait for.
|
||||
"""
|
||||
|
||||
future = asyncio.Future(loop=self.loop)
|
||||
future = compat.create_future(self.loop)
|
||||
entry = EventListener(event=event, predicate=predicate, result=result, future=future)
|
||||
self._dispatch_listeners.append(entry)
|
||||
return future
|
||||
|
@ -739,7 +739,7 @@ class ConnectionState:
|
||||
return Message(state=self, channel=channel, data=data)
|
||||
|
||||
def receive_chunk(self, guild_id):
|
||||
future = asyncio.Future(loop=self.loop)
|
||||
future = compat.create_future(self.loop)
|
||||
listener = Listener(ListenerType.chunk, future, lambda s: s.id == guild_id)
|
||||
self._listeners.append(listener)
|
||||
return future
|
||||
|
Loading…
x
Reference in New Issue
Block a user