Implement async checks. Fixes #380.

This commit is contained in:
Rapptz
2017-02-12 12:13:23 -05:00
parent 2abdbc70c2
commit 47ef657fbd
5 changed files with 83 additions and 40 deletions

View File

@ -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