sse

package
v0.0.0-...-2d2b8e1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 1, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

This package contains the Server Sent Events implementation used by horizon.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pumped

func Pumped() <-chan struct{}

Pumped returns a channel that will be closed the next time the input pump sends. It can be used similar to `ctx.Done()`, like so: `<-sse.Pumped()`

func Tick

func Tick()

Tick triggers any open SSE streams to tick by replacing and closing the `nextTick` trigger channel.

func WriteEvent

func WriteEvent(ctx context.Context, w http.ResponseWriter, e Event)

WriteEvent does the actual work of formatting an SSE compliant message sending it over the provided ResponseWriter and flushing.

func WritePreamble

func WritePreamble(ctx context.Context, w http.ResponseWriter) bool

WritePreamble prepares this http connection for streaming using Server Sent Events. It sends the initial http response with the appropriate headers to do so.

Types

type Event

type Event struct {
	Data  interface{}
	Error error
	ID    string
	Event string
	Retry int
}

Event is the packet of data that gets sent over the wire to a connected client.

func (Event) SseEvent

func (e Event) SseEvent() Event

SseEvent returns the SSE compatible form of the Event... itself.

type Eventable

type Eventable interface {
	// SseEvent returns the SSE compatible form of the implementer
	SseEvent() Event
}

Eventable represents an object that can be converted to an SSE compatible event.

type Stream

type Stream interface {
	Send(Event)
	SentCount() int
	Done()
	SetLimit(limit int)
	IsDone() bool
	Err(error)
}

Stream represents an output stream that data can be written to

func NewStream

func NewStream(ctx context.Context, w http.ResponseWriter, r *http.Request) Stream

NewStream creates a new stream against the provided response writer

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL