Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithCancel ¶ added in v0.9.88
func WithCancel[T any](cancel context.CancelFunc) func(*EventStream[T])
WithCancel hands ownership of a context cancel function (typically the request timeout's) to the stream. The deadline keeps bounding the whole stream; the stream releases the context when it ends or is closed instead of the caller cancelling it before iteration. A nil cancel is ignored.
func WithDataRequired ¶
func WithDataRequired[T any](dataRequired bool) func(*EventStream[T])
Types ¶
type EventStream ¶
type EventStream[T any] struct { // contains filtered or unexported fields }
func NewEventStream ¶
func NewEventStream[T any]( ctx context.Context, source io.Reader, unmarshaller func(se []byte) (T, error), sentinel string, opts ...func(*EventStream[T]), ) *EventStream[T]
func (*EventStream[T]) Close ¶
func (es *EventStream[T]) Close() error
Close will release underlying resources held by an event stream. It must always be called.
func (*EventStream[T]) Err ¶
func (es *EventStream[T]) Err() error
Err returns the first non-EOF error that was encountered
func (*EventStream[T]) Next ¶
func (es *EventStream[T]) Next() bool
Next waits for the next event from a stream which will be available through the Value() method. It returns false when the stream is done or an error occurred. After this method returns false, the Err method is used to check for any errors that occurred while parsing the stream.
func (*EventStream[T]) RawValue ¶ added in v0.9.88
func (es *EventStream[T]) RawValue() json.RawMessage
RawValue returns the JSON that Value was decoded from: the frame's event, data and retry, plus the last event id seen.
func (*EventStream[T]) Value ¶
func (es *EventStream[T]) Value() *T
Value returns the most recent event that was generated from a call to Next
type ServerEvent ¶
type ServerEvent struct {
ID *string `json:"id,omitempty"`
Event *string `json:"event,omitempty"`
Data json.RawMessage `json:"data,omitempty"`
Retry *int64 `json:"retry,omitempty"`
}