common

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidApp = fmt.Errorf("invalid application provided")

ErrInvalidApp is returned by triggers when a non-existent app is requested.

View Source
var ErrNoChannel = fmt.Errorf("no channel to send request")

ErrNoChannel is returned when the go routine is stopped.

Functions

This section is empty.

Types

type Action

type Action struct {
	Name TriggerName
	Fn   func(website.EventType) // most actions use this for triggers.
	C    chan website.EventType  // if provided, T is optional.
	T    *time.Ticker            // if provided, C is optional.
	Hide bool                    // prevent logging.
}

Action defines a trigger/timer that can be executed.

type Config

type Config struct {
	*website.Server // send trigger responses to website.
	*website.ClientInfo
	Snapshot *snapshot.Config
	Apps     *apps.Apps
	Serial   bool
	mnd.Logger
	// contains filtered or unexported fields
}

Config is the input data shared by most triggers. Everything is mandatory.

func (*Config) Add

func (c *Config) Add(action ...*Action)

Add adds a new action to our list of "Actions to run." actions are timers or triggers, or both.

func (*Config) Exec

func (c *Config) Exec(event website.EventType, name TriggerName) bool

Exec runs a trigger. This is abastraction method used in a bunch of places.

func (*Config) Get

func (c *Config) Get(name TriggerName) *Action

Get a trigger by unique name. May return nil, and that could cause a panic. We avoid panics by using a custom type with corresponding constants as input.

func (*Config) Run

func (c *Config) Run()

Run converts all the tickers and triggers into []reflect.SelectCase. This allows us to run a loop with a dynamic number of channels and tickers to watch.

func (*Config) Stop

func (c *Config) Stop(event website.EventType)

Stop shuts down the loop/goroutine that handles all triggers and timers.

type TriggerName

type TriggerName string

TriggerName makes sure triggers have a known name.

const TrigStop TriggerName = "Stopping all triggers and timers (reload)."

TrigStop is used to signal a stop/reload.

func (TriggerName) WithInstance added in v0.3.3

func (name TriggerName) WithInstance(instance int) TriggerName

WithInstance returns a trigger name with an instance ID.

Jump to

Keyboard shortcuts

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