aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2017-01-25 21:38:50 -0500
committerRapptz <[email protected]>2017-01-25 21:38:50 -0500
commitb876133e87b29a6959eb766d006fa6b57db1037e (patch)
tree420643e1d71aaefc460f36ffe421c1a8108d54a3
parentRemove unused ChannelPermissions namedtuple. (diff)
downloaddiscord.py-b876133e87b29a6959eb766d006fa6b57db1037e.tar.xz
discord.py-b876133e87b29a6959eb766d006fa6b57db1037e.zip
Add compatibility shim for asyncio.Future creation.
Should provide better support for uvloop.
-rw-r--r--discord/client.py4
-rw-r--r--discord/compat.py9
-rw-r--r--discord/gateway.py2
-rw-r--r--discord/state.py2
4 files changed, 13 insertions, 4 deletions
diff --git a/discord/client.py b/discord/client.py
index d2819ce2..ec05cb20 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -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))
diff --git a/discord/compat.py b/discord/compat.py
index 43294254..3b9e66ff 100644
--- a/discord/compat.py
+++ b/discord/compat.py
@@ -32,6 +32,15 @@ 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:
# the following code is slightly modified from the
diff --git a/discord/gateway.py b/discord/gateway.py
index e88021c9..9897ca42 100644
--- a/discord/gateway.py
+++ b/discord/gateway.py
@@ -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
diff --git a/discord/state.py b/discord/state.py
index 6b6a8fc6..1a511161 100644
--- a/discord/state.py
+++ b/discord/state.py
@@ -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