diff options
| author | Rapptz <[email protected]> | 2017-02-12 12:13:23 -0500 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2017-02-12 12:13:23 -0500 |
| commit | 47ef657fbd84d3fc89d9ef012c4c5c8d4318d4fd (patch) | |
| tree | 451d6652cdbe5d59e162063ea6bb911d46421713 /discord/utils.py | |
| parent | Implement utilities for AsyncIterator. (diff) | |
| download | discord.py-47ef657fbd84d3fc89d9ef012c4c5c8d4318d4fd.tar.xz discord.py-47ef657fbd84d3fc89d9ef012c4c5c8d4318d4fd.zip | |
Implement async checks. Fixes #380.
Diffstat (limited to 'discord/utils.py')
| -rw-r--r-- | discord/utils.py | 16 |
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 |