Generator that yields JSON data as SSE
()
| 74 | import json |
| 75 | |
| 76 | def json_event_generator(): |
| 77 | """Generator that yields JSON data as SSE""" |
| 78 | for i in range(5): |
| 79 | data = {"id": i, "message": f"JSON message {i}", "timestamp": time.time(), "type": "notification"} |
| 80 | yield SSEMessage(json.dumps(data), event="notification", id=str(i)) |
| 81 | time.sleep(2) |
| 82 | |
| 83 | return SSEResponse(json_event_generator()) |
| 84 |
no test coverage detected