Struct uhttp_sse::SseMessage
[−]
[src]
pub struct SseMessage<W: Write>(_);
An SSE message.
Each message consists of any number of fields followed by a message terminating
sequence. The member functions allow "appending" a field to the message any number of
times, and when the SseMessage
goes out of scope, the message is flushed and
terminated.
Methods
impl<W: Write> SseMessage<W>
[src]
fn new(stream: W) -> Self
Create a new SseMessage
to write into the given stream.
fn data(&mut self) -> Result<SseField<&mut W>>
Append a data field.
This is the data payload passed into the browser event listener callback when the message is terminated. It can be raw text, JSON, or any other format. If a message contains multiple data fields, the browser concatenates their values until the end of the message.
This field is the only "required" one, in that a message with an empty data field won't trigger any event listener in the browser.
fn event(&mut self) -> Result<SseField<&mut W>>
Append an event name field.
This optional field tags the current message with an event name, which causes the browser to trigger an event listener specifically for that event.
fn id(&mut self) -> Result<SseField<&mut W>>
Append an event ID field.
This optional field sets the "last event ID" of the current event stream.
fn retry(&mut self) -> Result<SseField<&mut W>>
Append a retry field.
This optional field must be an integer and sets the reconnection time of the current event stream, which is the millisecond delay used when the browser attempts to reestablish a connection to the stream.
fn finish(&mut self) -> Result<()>
Terminate the current message and begin a new one.
Trait Implementations
impl<W: Write> Drop for SseMessage<W>
[src]
Writes the message terminating sequence and flushes on drop.