observing

package
v0.0.0-...-1dd1f65 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package observing contains plumbing for the tester's implementation of the observer pattern.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotSlice occurs when CheckObservers is passed something other than a slice.
	ErrNotSlice = errors.New("not an observer slice")

	// ErrObserverNil occurs when CheckObservers is passed a nil observer.
	ErrObserverNil = errors.New("observer nil")
)

Functions

func CheckObservers

func CheckObservers(obs interface{}) error

CheckObservers does some cursory checking of the observer slice obs (currently just nil checking).

Types

type Batch

type Batch struct {
	// Kind is the kind of batch message being shown.
	Kind BatchKind `json:"kind"`

	// Num contains, in a start message, the number of items to expect in the batch.
	// In a step message, if set, it identifies the index of the item.
	Num int `json:"num"`
}

Batch is a mixin struct for observer messages that represent 'batch runs'.

func NewBatchEnd

func NewBatchEnd() Batch

NewBatchEnd makes a batch end mixin.

func NewBatchStart

func NewBatchStart(n int) Batch

NewBatchStart makes a batch start mixin with total count n.

func NewBatchStep

func NewBatchStep(i int) Batch

NewBatchStep makes a batch step mixin with current index i.

type BatchKind

type BatchKind uint8

BatchKind is the enumeration of kinds of batch message.

const (
	// BatchStart represents a message that represents the start of a batch run.
	BatchStart BatchKind = iota
	// BatchStep represents a message that represents a single step in a batch run.
	BatchStep
	// BatchEnd represents a message that represents the end of a batch run.
	BatchEnd
)

type FanIn

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

FanIn is a low-level, reflection-based device for forwarding observations from multiple concurrent sources to a single handler.

func NewFanIn

func NewFanIn(f func(i int, input interface{}) error, cap int) *FanIn

NewFanIn creates a fan-in with the given handling function f and capacity hint cap.

func (*FanIn) Add

func (f *FanIn) Add(ch interface{})

Add adds a channel to a fan-in.

func (*FanIn) Run

func (f *FanIn) Run(ctx context.Context) error

Run runs the fan-in on context ctx. It is not re-entrant.

Jump to

Keyboard shortcuts

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