Class SseEventReader
- Namespace
- SseAssertions
- Assembly
- SseAssertions.dll
Reads Server-Sent Events from a Stream one at a time, as they arrive. Use it for a stream that never ends: read until the events you need have arrived, then stop, instead of waiting for the end of the stream or a timeout. The parsing rules are those of Parse(string).
public sealed class SseEventReader
- Inheritance
-
SseEventReader
- Inherited Members
Remarks
The body is decoded as UTF-8, as the SSE specification requires; a leading byte order mark is skipped.
On an SseStream, every reader shares the stream's position: a reader created after another one stopped continues with the next event, and no bytes are lost between them. On another stream, a reader buffers ahead; once you stop using it, read the rest of the stream through the same reader.
Not thread-safe.
Constructors
SseEventReader(Stream)
Initializes a reader over stream.
public SseEventReader(Stream stream)
Parameters
Exceptions
- ArgumentNullException
streamis null.
Properties
BytesRead
Gets the number of bytes this reader has read from the stream.
public long BytesRead { get; }
Property Value
TextExcerpt
Gets the start of the text this reader has decoded (about the first 256 characters, lines
joined by \n), for failure messages.
public string TextExcerpt { get; }
Property Value
Methods
ReadAsync(CancellationToken)
Reads the next event, waiting until a complete one has arrived. A frame without a data:
line is skipped, as the SSE specification requires.
public ValueTask<SseEvent?> ReadAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenCancels the wait for the next event.
Returns
Exceptions
- OperationCanceledException
cancellationTokenwas canceled first.