heart

package
v2.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2021 License: ISC Imports: 4 Imported by: 0

Documentation

Overview

Package heart implements a general purpose pacemaker.

Index

Constants

This section is empty.

Variables

View Source
var Debug = func(v ...interface{}) {}

Debug is the default logger that Pacemaker uses.

View Source
var ErrDead = errors.New("no heartbeat replied")

Functions

This section is empty.

Types

type AtomicDuration

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

AtomicDuration is a thread-safe Duration guarded by atomic.

func (*AtomicDuration) Get

func (d *AtomicDuration) Get() time.Duration

func (*AtomicDuration) Set

func (d *AtomicDuration) Set(dura time.Duration)

type AtomicTime

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

AtomicTime is a thread-safe UnixNano timestamp guarded by atomic.

func (*AtomicTime) Get

func (t *AtomicTime) Get() int64

func (*AtomicTime) Set

func (t *AtomicTime) Set(time time.Time)

func (*AtomicTime) Time

func (t *AtomicTime) Time() time.Time

type Pacemaker

type Pacemaker struct {
	// Heartrate is the received duration between heartbeats.
	Heartrate AtomicDuration

	Ticks <-chan time.Time

	// Time in nanoseconds, guarded by atomic read/writes.
	SentBeat AtomicTime
	EchoBeat AtomicTime

	// Any callback that returns an error will stop the pacer.
	Pacer func(context.Context) error
	// contains filtered or unexported fields
}

Pacemaker is the internal pacemaker state. All fields are not thread-safe unless they're atomic.

func NewPacemaker

func NewPacemaker(heartrate time.Duration, pacer func(context.Context) error) Pacemaker

func (*Pacemaker) Dead

func (p *Pacemaker) Dead() bool

Dead, if true, will have Pace return an ErrDead.

func (*Pacemaker) Echo

func (p *Pacemaker) Echo()

func (*Pacemaker) Pace

func (p *Pacemaker) Pace() error

pace sends a heartbeat with the appropriate timeout for the context.

func (*Pacemaker) PaceCtx

func (p *Pacemaker) PaceCtx(ctx context.Context) error

func (*Pacemaker) SetPace

func (p *Pacemaker) SetPace(heartrate time.Duration)

SetHeartRate sets the ticker's heart rate.

func (*Pacemaker) StopTicker

func (p *Pacemaker) StopTicker()

Stop stops the pacemaker, or it does nothing if the pacemaker is not started.

Jump to

Keyboard shortcuts

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