heart

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2020 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 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 time.Duration

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

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

func NewPacemaker

func NewPacemaker(heartrate time.Duration, pacer func() 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) StartAsync

func (p *Pacemaker) StartAsync(wg *sync.WaitGroup) (death chan error)

StartAsync starts the pacemaker asynchronously. The WaitGroup is optional.

func (*Pacemaker) Stop

func (p *Pacemaker) Stop()

Jump to

Keyboard shortcuts

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