added await

This commit is contained in:
Kristian Krsnik 2024-04-12 18:02:14 +02:00
parent c952bd921f
commit 9e83da6b1a
Signed by: Kristian
GPG Key ID: FD1330AC9F909E85

View File

@ -1,4 +1,5 @@
import json
import asyncio
def convert_to_bytes(size: int | str) -> int:
try:
@ -23,11 +24,19 @@ def convert_to_bytes(size: int | str) -> int:
async def generate_data(size: int, buffer_size: int = 4 * 1024) -> bytes:
size_left = size
# https://github.com/tiangolo/fastapi/issues/5183
# https://github.com/encode/starlette/discussions/1776#discussioncomment-3207518
try:
while size_left > buffer_size:
size_left -= buffer_size
yield b'\0' * buffer_size
await asyncio.sleep(0)
else:
yield b'\0' * size_left
await asyncio.sleep(0)
except asyncio.CancelledError:
raise GeneratorExit
def check_policies(ip: str) -> None: