7/17
Part 3 of 7 · Runs and streamsLearn and do
A dropped connection resumes from its last event id
SSE gives each event an optional id. The WHATWG spec's example shows the point: if the connection dies after the event with id 1, the browser reconnects and sends a Last-Event-ID header with the value 1. The server then sends only what came after.
# (id, text)
events = [(1, "Yes,"), (2, " the"), (3, " tent"), (4, " is"), (5, " waterproof"), (6, ".")]
def resume(events: list, last_event_id: int) -> str:
"""The text a client that reconnects with Last-Event-ID still needs."""
return "".join(text for i, text in events if i > last_event_id)
# the connection drops after event 3
shown = "".join(text for i, text in events if i <= 3)
print(repr(shown), "+", repr(resume(events, 3)))
The phone loses signal after event 3. By the time it reconnects with Last-Event-ID 3, the model has finished. Does the server call the model again?
Pick one to see what it prints.
Pick an answer above to see the rest