timer

package
v1.18.5 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Gate

type Gate interface {
	// FireChan return the channel which will be fired when time is up
	FireChan() <-chan struct{}
	// FireAfter check will the timer get fired after a certain time
	FireAfter(now time.Time) bool
	// Update update the timer gate, return true if update is a success
	// success means timer is idle or timer is set with a sooner time to fire
	Update(nextTime time.Time) bool
	// Close shutdown the timer
	Close()
}

Gate interface

type LocalGate

type LocalGate interface {
	Gate
}

func NewLocalGate

func NewLocalGate(timeSource clock.TimeSource) LocalGate

NewLocalGate create a new timer gate instance

type LocalGateImpl

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

func (*LocalGateImpl) Close

func (timerGate *LocalGateImpl) Close()

Close shutdown the timer

func (*LocalGateImpl) FireAfter

func (timerGate *LocalGateImpl) FireAfter(now time.Time) bool

FireAfter check will the timer get fired after a certain time

func (*LocalGateImpl) FireChan

func (timerGate *LocalGateImpl) FireChan() <-chan struct{}

FireChan return the channel which will be fired when time is up

func (*LocalGateImpl) Update

func (timerGate *LocalGateImpl) Update(nextTime time.Time) bool

Update update the timer gate, return true if update is a success success means timer is idle or timer is set with a sooner time to fire

type RemoteGate

type RemoteGate interface {
	Gate
	// SetCurrentTime set the current time, and additionally fire the fire chan
	// if new "current" time is after the next wakeup time, return true if
	// "current" is actually updated
	SetCurrentTime(nextTime time.Time) bool
}

func NewRemoteGate

func NewRemoteGate() RemoteGate

NewRemoteGate create a new timer gate instance

type RemoteGateImpl

type RemoteGateImpl struct {

	// lock for timer and next wakeup time
	sync.Mutex
	// contains filtered or unexported fields
}

func (*RemoteGateImpl) Close

func (timerGate *RemoteGateImpl) Close()

Close shutdown the timer

func (*RemoteGateImpl) FireAfter

func (timerGate *RemoteGateImpl) FireAfter(now time.Time) bool

FireAfter check will the timer get fired after a certain time

func (*RemoteGateImpl) FireChan

func (timerGate *RemoteGateImpl) FireChan() <-chan struct{}

FireChan return the channel which will be fired when time is up

func (*RemoteGateImpl) SetCurrentTime

func (timerGate *RemoteGateImpl) SetCurrentTime(currentTime time.Time) bool

SetCurrentTime set the current time, and additionally fire the fire chan if new "current" time is after the next wake up time, return true if "current" is actually updated

func (*RemoteGateImpl) Update

func (timerGate *RemoteGateImpl) Update(nextTime time.Time) bool

Update update the timer gate, return true if update is a success success means timer is idle or timer is set with a sooner time to fire

Jump to

Keyboard shortcuts

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