From 47ef657fbd84d3fc89d9ef012c4c5c8d4318d4fd Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sun, 12 Feb 2017 12:13:23 -0500 Subject: Implement async checks. Fixes #380. --- discord/utils.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'discord/utils.py') 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) +@asyncio.coroutine +def maybe_coroutine(f, e): + if asyncio.iscoroutinefunction(f): + return (yield from f(e)) + else: + return f(e) + +@asyncio.coroutine +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 -- cgit v1.2.3