events

package
v0.27.2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: Apache-2.0 Imports: 2 Imported by: 3

Documentation

Overview

Package events provides functionalities for packages to log their states as events for others to consume and display to end users in meaningful ways.

Index

Constants

View Source
const DefaultBufferSize = 50

DefaultBufferSize defines the default maximum number of events that the bus can cache before they are handled.

View Source
const (
	GroupError = "error"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bus

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

Bus defines a bus to send and receive events.

func NewBus

func NewBus(options ...BusOption) Bus

NewBus creates a new event bus.

func (Bus) Events

func (b Bus) Events() <-chan Event

Events returns a read only channel to read the events.

func (Bus) Send

func (b Bus) Send(message string, options ...Option)

Send sends a new event to bus. This method will block if the event bus buffer is full.

func (Bus) SendError added in v0.25.0

func (b Bus) SendError(err error, options ...Option)

SendError sends an error event to the bus.

func (Bus) SendInfo added in v0.25.0

func (b Bus) SendInfo(message string, options ...Option)

SendInfo sends an info event to the bus.

func (Bus) SendView added in v0.25.0

func (b Bus) SendView(s fmt.Stringer, options ...Option)

SendView sends a new event for a view to the bus. Views are types that implement the `fmt.Stringer` interface which allow events with complex message formats.

func (Bus) Sendf added in v0.25.0

func (b Bus) Sendf(format string, a ...any)

Sendf sends a new event with a formatted message to bus.

func (*Bus) Stop added in v0.25.0

func (b *Bus) Stop()

Stop stops the event bus. All new events are ignored once the event bus is stopped.

type BusOption

type BusOption func(*Bus)

BusOption configures the Bus.

func WithBufferSize added in v0.25.0

func WithBufferSize(size int) BusOption

WithBufferSize assigns the size of the buffer to use for buffering events.

type Event

type Event struct {
	ProgressIndication ProgressIndication
	Icon               string
	Message            string
	Verbose            bool
	Group              string
}

Event represents a state.

func New

func New(message string, options ...Option) Event

New creates a new event with given config.

func (Event) InProgress added in v0.25.0

func (e Event) InProgress() bool

InProgress returns true when the event is in progress.

func (Event) String added in v0.25.0

func (e Event) String() string

type Option

type Option func(*Event)

Option event options.

func Group added in v0.26.0

func Group(name string) Option

Group sets a group name for the event.

func Icon

func Icon(icon string) Option

Icon sets the text icon prefix.

func ProgressFinish added in v0.26.0

func ProgressFinish() Option

ProgressFinish indicates that a status event finished the ongoing task.

func ProgressStart added in v0.26.0

func ProgressStart() Option

ProgressStart indicates that a status event starts the progress indicator.

func ProgressUpdate added in v0.26.0

func ProgressUpdate() Option

ProgressUpdate indicates that a status event updated the current progress.

func Verbose added in v0.25.0

func Verbose() Option

Verbose sets high verbosity for the Event.

type ProgressIndication added in v0.25.0

type ProgressIndication uint8

ProgressIndication enumerates possible states of progress indication for an Event.

const (
	IndicationNone ProgressIndication = iota
	IndicationStart
	IndicationUpdate
	IndicationFinish
)

type Provider added in v0.26.0

type Provider interface {
	// Events returns a read only channel to read the events.
	Events() <-chan Event
}

Provider defines an interface for event providers.

Jump to

Keyboard shortcuts

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