Help us shape the future of Go! Take the 2026 Go Developer Survey

control

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package control holds the controls sent to a running loop: stop, inject a message, change settings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Control

type Control struct {
	Kind    Kind
	Message string       // for Inject
	Change  state.Change // for ModifyConfig
}

Control is one queued control.

type Inbox

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

Inbox queues controls until the loop is ready for them. Stop has its own channel so it can never be lost to a full queue.

func New

func New(settings Settings) *Inbox

func (*Inbox) Drain

func (in *Inbox) Drain(n Notifier) bool

Drain applies every queued control and tells n about each. It returns true when one of them was a stop.

func (*Inbox) Send

func (in *Inbox) Send(c Control) bool

Send queues a control. It returns false when the queue is full.

func (*Inbox) Stop

func (in *Inbox) Stop()

Stop asks the loop to stop. Safe to call more than once.

func (*Inbox) StopRequested

func (in *Inbox) StopRequested() bool

func (*Inbox) WaitInject

func (in *Inbox) WaitInject(ctx context.Context) (string, bool)

WaitInject blocks until an Inject arrives and returns its message. ok is false when the loop is stopped or ctx ends first. Setting changes that arrive meanwhile are applied without notice.

type Kind

type Kind int

Kind classifies a control.

const (
	Stop Kind = iota
	Inject
	ModifyConfig
)

type Notifier

type Notifier interface {
	Injected(message string)
	ConfigChanged()
}

Notifier hears about controls applied between iterations. → engine.Engine

type Settings

type Settings interface {
	Apply(c state.Change)
}

Settings receives setting changes. → state.Run

Jump to

Keyboard shortcuts

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