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:
parent
327758f00f
commit
1dbf774d55
1 changed files with 2 additions and 3 deletions
|
@ -9,11 +9,10 @@ class CustomLogsHandler:
|
||||||
logs = []
|
logs = []
|
||||||
self.logs = logs # Initialize logs to store data
|
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."""
|
"""Send JSON data and log it."""
|
||||||
self.logs.append(data) # Append data to logs
|
self.logs.append(data) # Append data to logs
|
||||||
print(f"My custom Log: {data}")
|
print(f"My custom Log: {data}")
|
||||||
yield f"My custom Log: {data}"
|
|
||||||
|
|
||||||
class ReportGenerator:
|
class ReportGenerator:
|
||||||
def __init__(self, query: str, report_type: str):
|
def __init__(self, query: str, report_type: str):
|
||||||
|
@ -64,6 +63,6 @@ class ReportGenerator:
|
||||||
if self._log_index < len(self.logs):
|
if self._log_index < len(self.logs):
|
||||||
log = self.logs[self._log_index]
|
log = self.logs[self._log_index]
|
||||||
self._log_index += 1
|
self._log_index += 1
|
||||||
return log # Return the next log
|
yield log # Return the next log
|
||||||
else:
|
else:
|
||||||
raise StopAsyncIteration # Stop when logs are exhausted
|
raise StopAsyncIteration # Stop when logs are exhausted
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue