bus

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2016 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Publish

func Publish(c context.Context, event *Event)

Publish broadcasts an event to all subscribers.

func Subscribe

func Subscribe(c context.Context, eventc chan *Event)

Subscribe adds the channel to the list of subscribers. Each subscriber in the list will receive broadcast events.

func ToContext

func ToContext(c Setter, b Bus)

ToContext adds the Bus to this context if it supports the Setter interface.

func Unsubscribe

func Unsubscribe(c context.Context, eventc chan *Event)

Unsubscribe removes the channel from the list of subscribers.

Types

type Bus

type Bus interface {
	// Publish broadcasts an event to all subscribers.
	Publish(*Event)

	// Subscribe adds the channel to the list of
	// subscribers. Each subscriber in the list will
	// receive broadcast events.
	Subscribe(chan *Event)

	// Unsubscribe removes the channel from the list
	// of subscribers.
	Unsubscribe(chan *Event)
}

Bus represents an event bus implementation that allows a publisher to broadcast Event notifications to a list of subscribers.

func FromContext

func FromContext(c context.Context) Bus

FromContext returns the Bus associated with this context.

func New

func New() Bus

New creates a simple event bus that manages a list of subscribers to which events are published.

type Event

type Event struct {
	Type  EventType   `json:"type"`
	Repo  model.Repo  `json:"repo"`
	Build model.Build `json:"build"`
	Job   model.Job   `json:"job"`
}

Event represents a build event.

func NewBuildEvent

func NewBuildEvent(t EventType, r *model.Repo, b *model.Build) *Event

func NewEvent

func NewEvent(t EventType, r *model.Repo, b *model.Build, j *model.Job) *Event

NewEvent creates a new Event for the build, using copies of the build data to avoid possible mutation or race conditions.

type EventType

type EventType string

EventType defines the possible types of build events.

const (
	Enqueued  EventType = "enqueued"
	Started   EventType = "started"
	Finished  EventType = "finished"
	Cancelled EventType = "cancelled"
)

type Setter

type Setter interface {
	Set(string, interface{})
}

Setter defines a context that enables setting values.

Jump to

Keyboard shortcuts

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