catchall

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2020 License: Apache-2.0 Imports: 4 Imported by: 6

README

catchall

All kinds of golang shenanigans

Documentation

Overview

Package lib contains convenience functionality for repeated tasks, e.g. implementing the observer pattern.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckFatal

func CheckFatal(message string, err error)

CheckFatal checks the given error, logs it in a canonical format and exists the program.

func SigAbort

func SigAbort(ready chan bool, abort chan os.Signal) chan bool

SigAbort waits for a value on the ready channel. Waiting is be aborted, when a value is received on the abort channel first. It returns a channel that receives a value when either condition has been met, true if ready was first to receive, true otherwise.

Types

type ConcurrentObservable

type ConcurrentObservable struct {
	DataLock     sync.RWMutex
	ObserverLock sync.Mutex
	// contains filtered or unexported fields
}

ConcurrentObservable enables KeyObservable functionality. It may be used as a mixin to enable observability.

func NewConcurrentObservable

func NewConcurrentObservable() ConcurrentObservable

NewConcurrentObservable constructs a new ConcurrentObservable.

func (ConcurrentObservable) Notify

func (l ConcurrentObservable) Notify(k Key)

func (ConcurrentObservable) Observe

func (l ConcurrentObservable) Observe(k Key) chan bool

type Key

type Key fmt.Stringer

Key may be any type that can be marshaled into plain-text

type KeyObservable

type KeyObservable interface {
	// Observe registers a new observer for the given key.
	// The returned channel will receive a bool each time the observed key changes.
	Observe(k Key) chan bool
	// Notify notifies all registered observers of the given key of a change to the key.
	Notify(k Key)
}

KeyObservable is a collection of key-addressable things, where each key may be observed for changes.

type PlainKey

type PlainKey struct {
	Text string
}

PlainKey is a box for plain strings so that they may be used as Key type.

func NewPlainKey

func NewPlainKey(s string) PlainKey

NewPlainKey constructs a PlainKey from a plain string.

func (PlainKey) String

func (pk PlainKey) String() string

String marshals PlainKey into a string.

Jump to

Keyboard shortcuts

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