torus-cli: github.com/manifoldco/torus-cli/daemon/observer Index | Files

package observer

import "github.com/manifoldco/torus-cli/daemon/observer"

Package observer provides a facility for publishing progress updates and state changes from parts of the daemon, an a SSE http handler for consumers of these events.

Index

Package Files

observer.go

Variables

var CtxRequestID ctxkey = "id"

CtxRequestID is the context WithValue key for a request id.

type EventType Uses

type EventType string

EventType represents all possible types of events that can be observed.

const (
    Progress EventType = "progress"
    Started  EventType = "started"
    Finished EventType = "finished"
    Errored  EventType = "errored"
    Aborted  EventType = "aborted"
)

All values for EventType

type Notifier Uses

type Notifier struct {
    sync.RWMutex
    // contains filtered or unexported fields
}

Notifier belongs to a transactions and represents one segment in a series of actions. A Notifier can send many messages.

func (*Notifier) Notifier Uses

func (n *Notifier) Notifier(total uint) *Notifier

Notifier creates a child notifier to this Notifier

func (*Notifier) Notify Uses

func (n *Notifier) Notify(eventType EventType, message string, increment bool)

Notify publishes an event to all SSE observers. This function panics when it is called more often than it is supposed to have been called.

type Observer Uses

type Observer struct {
    // contains filtered or unexported fields
}

Observer receives events via Notify, and publishes them as SSEs via its ServeHTTP function.

func New Uses

func New() *Observer

New returns a new initialized Observer

func (*Observer) Notifier Uses

func (o *Observer) Notifier(ctx context.Context, total uint) (*Notifier, error)

Notifier creates a new transaction for sending notifications

func (*Observer) ServeHTTP Uses

func (o *Observer) ServeHTTP(rw http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface for providing server-sent events of observed notifications.

func (*Observer) Start Uses

func (o *Observer) Start()

Start begins listening for notifications of observable events. It returns after stop has been called.

func (*Observer) Stop Uses

func (o *Observer) Stop()

Stop terminates propagation of events through the observer

Package observer imports 7 packages (graph) and is imported by 6 packages. Updated 2016-12-15. Refresh now. Tools for package owners.