aboutsummaryrefslogtreecommitdiff
path: root/discord/utils.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2017-02-12 12:13:23 -0500
committerRapptz <[email protected]>2017-02-12 12:13:23 -0500
commit47ef657fbd84d3fc89d9ef012c4c5c8d4318d4fd (patch)
tree451d6652cdbe5d59e162063ea6bb911d46421713 /discord/utils.py
parentImplement utilities for AsyncIterator. (diff)
downloaddiscord.py-47ef657fbd84d3fc89d9ef012c4c5c8d4318d4fd.tar.xz
discord.py-47ef657fbd84d3fc89d9ef012c4c5c8d4318d4fd.zip
Implement async checks. Fixes #380.
Diffstat (limited to 'discord/utils.py')
-rw-r--r--discord/utils.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/discord/utils.py b/discord/utils.py
index 1db8e4e0..fe1129d7 100644
--- a/discord/utils.py
+++ b/discord/utils.py
@@ -260,3 +260,19 @@ def _bytes_to_base64_data(data):
def to_json(obj):
return json.dumps(obj, separators=(',', ':'), ensure_ascii=True)
+def maybe_coroutine(f, e):
+ if asyncio.iscoroutinefunction(f):
+ return (yield from f(e))
+ else:
+ return f(e)
+
+def async_all(gen):
+ check = asyncio.iscoroutine
+ for elem in gen:
+ if check(elem):
+ elem = yield from elem
+ if not elem:
+ return False
+ return True