Simulate concurrent API streaming with `lorem_stream`
mainThe lorem_stream example demonstrates how to use Reflex background tasks to concurrently generate and stream data (simulating multiple API calls) to the UI as it becomes available.
It manages multiple concurrent tasks by storing state in dictionaries keyed by a unique task_id. For each task, the state tracks:
running: bool: Indicates if the task should continue processing.progress: int: The number of iterations completed.end_at: int: The target number of iterations before the task stops.text: str: The accumulated generated text.