watchdog

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package watchdog fires when it is not kicked in time. Its timeout event carries the generation of the timer that expired, so Fire itself tells a stale timeout from the current one: the check is in verified code, not in the holder.

Index

Constants

View Source
const MaxGen = ^uint64(0)

MaxGen is the last generation. Arming or kicking past it is refused, never wrapped: a wrapped generation could match a timer still in flight.

Variables

This section is empty.

Functions

This section is empty.

Types

type Actions

type Actions uint64

Actions is the set of things the holder must do after a transition, one bit each. The holder performs them in declaration order. The zero value is the empty set.

const (
	ActStartTimer Actions = 1 << iota // start a timer tagged with Gen()
	ActCancelTimer
)

Actions values.

type Event

type Event struct {
	Kind EventKind
	Gen  uint64
}

Event is an input to Fire. Gen is meaningful for EvTimeout: the generation of the timer that expired.

type EventKind

type EventKind uint8

EventKind says what an event is.

const (
	EvArm EventKind
	EvKick
	EvTimeout
	EvStop
)

EventKind values.

type Machine

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

Machine is one watchdog. Build it with New and change it only with Fire.

func New

func New(start uint64) Machine

New returns an idle watchdog whose generations continue from start. A holder that restarts passes a start past every generation it handed out before, such as a persisted epoch, so a timer left over from the last run cannot match one from this run.

func (Machine) Fire

func (m Machine) Fire(e Event) (Machine, Actions, fsm.Outcome)

Fire applies e and returns the next machine, its actions and what happened.

func (Machine) Gen

func (m Machine) Gen() uint64

Gen returns the generation to tag a newly started timer with.

func (Machine) State

func (m Machine) State() State

State returns the control state.

type State

type State uint8

State is the watchdog's control state.

const (
	Idle State
	Armed
	Fired
)

State values. The zero value is an unexported sentinel.

func (State) String

func (s State) String() string

Jump to

Keyboard shortcuts

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