events

package
v0.13.9 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2016 License: MPL-2.0 Imports: 7 Imported by: 22

Documentation

Overview

Package events provides event subscription and polling functionality.

Index

Constants

View Source
const BufferSize = 64

Variables

View Source
var (
	ErrTimeout = errors.New("timeout")
	ErrClosed  = errors.New("closed")
)
View Source
var Default = NewLogger()

Functions

func Error

func Error(err error) *string

Error returns a string pointer suitable for JSON marshalling errors. It retains the "null on success" semantics, but ensures the error result is a string regardless of the underlying concrete error type.

Types

type BufferedSubscription

type BufferedSubscription interface {
	Since(id int, into []Event) []Event
}

func NewBufferedSubscription

func NewBufferedSubscription(s *Subscription, size int) BufferedSubscription

type Event

type Event struct {
	ID   int         `json:"id"`
	Time time.Time   `json:"time"`
	Type EventType   `json:"type"`
	Data interface{} `json:"data"`
}

type EventType

type EventType int
const (
	Ping EventType = 1 << iota
	Starting
	StartupComplete
	DeviceDiscovered
	DeviceConnected
	DeviceDisconnected
	DeviceRejected
	DevicePaused
	DeviceResumed
	LocalChangeDetected
	LocalIndexUpdated
	RemoteIndexUpdated
	ItemStarted
	ItemFinished
	StateChanged
	FolderRejected
	ConfigSaved
	DownloadProgress
	RemoteDownloadProgress
	FolderSummary
	FolderCompletion
	FolderErrors
	FolderScanProgress
	ListenAddressesChanged
	LoginAttempt

	AllEvents = (1 << iota) - 1
)

func (EventType) MarshalText

func (t EventType) MarshalText() ([]byte, error)

func (EventType) String

func (t EventType) String() string

type Logger

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

func NewLogger

func NewLogger() *Logger

func (*Logger) Log

func (l *Logger) Log(t EventType, data interface{})

func (*Logger) Subscribe

func (l *Logger) Subscribe(mask EventType) *Subscription

func (*Logger) Unsubscribe

func (l *Logger) Unsubscribe(s *Subscription)

type Subscription

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

func (*Subscription) C

func (s *Subscription) C() <-chan Event

func (*Subscription) Poll

func (s *Subscription) Poll(timeout time.Duration) (Event, error)

Poll returns an event from the subscription or an error if the poll times out of the event channel is closed. Poll should not be called concurrently from multiple goroutines for a single subscription.

Jump to

Keyboard shortcuts

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