Refactor async methods to adjust return types.

Changed `send_json` to return `None` instead of yielding and updated log retrieval to use `yield` in place of `return`. These modifications align function behavior with intended asynchronous use cases and improve consistency.
This commit is contained in:
ThomasTaroni 2025-04-25 18:46:48 +02:00
parent 327758f00f
commit 1dbf774d55

View file

@ -9,11 +9,10 @@ class CustomLogsHandler:
logs = []
self.logs = logs # Initialize logs to store data
async def send_json(self, data: Dict[str, Any]) -> AsyncGenerator[str, Any]:
async def send_json(self, data: Dict[str, Any]) -> None:
"""Send JSON data and log it."""
self.logs.append(data) # Append data to logs
print(f"My custom Log: {data}")
yield f"My custom Log: {data}"
class ReportGenerator:
def __init__(self, query: str, report_type: str):
@ -64,6 +63,6 @@ class ReportGenerator:
if self._log_index < len(self.logs):
log = self.logs[self._log_index]
self._log_index += 1
return log # Return the next log
yield log # Return the next log
else:
raise StopAsyncIteration # Stop when logs are exhausted