timer

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2022 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EstimateETA

func EstimateETA(startTime time.Time, progress, end uint64) time.Duration

EstimateETA attempts to estimate the remaining time for a job to finish given the [startTime] and it's current progress.

Types

type AdaptiveTimeoutConfig

type AdaptiveTimeoutConfig struct {
	InitialTimeout time.Duration `json:"initialTimeout"`
	MinimumTimeout time.Duration `json:"minimumTimeout"`
	MaximumTimeout time.Duration `json:"maximumTimeout"`
	// Timeout is [timeoutCoefficient] * average response time
	// [timeoutCoefficient] must be > 1
	TimeoutCoefficient float64 `json:"timeoutCoefficient"`
	// Larger halflife --> less volatile timeout
	// [timeoutHalfLife] must be positive
	TimeoutHalflife time.Duration `json:"timeoutHalflife"`
}

AdaptiveTimeoutConfig contains the parameters provided to the adaptive timeout manager.

type AdaptiveTimeoutManager

type AdaptiveTimeoutManager interface {
	// Start the timeout manager.
	// Must be called before any other method.
	// Must only be called once.
	Dispatch()
	// Stop the timeout manager.
	// Must only be called once.
	Stop()
	// Returns the current network timeout duration.
	TimeoutDuration() time.Duration
	// Registers a timeout for the item with the given [id].
	// If the timeout occurs before the item is Removed, [timeoutHandler] is called.
	Put(id ids.ID, op message.Op, timeoutHandler func())
	// Remove the timeout associated with [id].
	// Its timeout handler will not be called.
	Remove(id ids.ID)
	// ObserveLatency manually registers a response latency.
	// We use this to pretend that it a query to a benched validator
	// timed out when actually, we never even sent them a request.
	ObserveLatency(latency time.Duration)
}

func NewAdaptiveTimeoutManager

func NewAdaptiveTimeoutManager(
	config *AdaptiveTimeoutConfig,
	metricsNamespace string,
	metricsRegister prometheus.Registerer,
) (AdaptiveTimeoutManager, error)

type Meter

type Meter interface {
	// Notify this meter of a new event for it to rate
	Tick()
	// Return the number of events this meter is currently tracking
	Ticks() int
}

Meter tracks the number of occurrences of a specified event

type Repeater

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

func NewRepeater

func NewRepeater(handler func(), frequency time.Duration) *Repeater

func (*Repeater) Dispatch

func (r *Repeater) Dispatch()

func (*Repeater) Stop

func (r *Repeater) Stop()

type TimedMeter

type TimedMeter struct {

	// Can be used to fake time in tests
	Clock *mockable.Clock
	// Amount of time to keep a tick
	Duration time.Duration
	// contains filtered or unexported fields
}

TimedMeter is a meter that discards old events

func (*TimedMeter) Tick

func (tm *TimedMeter) Tick()

func (*TimedMeter) Ticks

func (tm *TimedMeter) Ticks() int

type TimeoutManager

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

TimeoutManager is a manager for timeouts.

func (*TimeoutManager) Dispatch

func (tm *TimeoutManager) Dispatch()

func (*TimeoutManager) Initialize

func (tm *TimeoutManager) Initialize(duration time.Duration)

Initialize is a constructor b/c Golang, in its wisdom, doesn't ... have them?

func (*TimeoutManager) Put

func (tm *TimeoutManager) Put(id ids.ID, handler func())

Put puts hash into the hash map

func (*TimeoutManager) Remove

func (tm *TimeoutManager) Remove(id ids.ID)

Remove the item that no longer needs to be there.

func (*TimeoutManager) Stop

func (tm *TimeoutManager) Stop()

Stop executing timeouts

func (*TimeoutManager) Timeout

func (tm *TimeoutManager) Timeout()

Timeout registers a timeout

type Timer

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

Timer wraps a timer object. This allows a user to specify a handler. Once specifying the handler, the dispatch thread can be called. The dispatcher will only return after calling Stop. SetTimeoutIn will result in calling the handler in the specified amount of time.

func NewStagedTimer

func NewStagedTimer(f func() (time.Duration, bool)) *Timer

NewStagedTimer returns a timer that will execute [f] when a timeout occurs and execute an additional timeout after the returned duration if [f] returns true and some duration.

func NewTimer

func NewTimer(handler func()) *Timer

NewTimer creates a new timer object

func (*Timer) Cancel

func (t *Timer) Cancel()

Cancel the currently scheduled event

func (*Timer) Dispatch

func (t *Timer) Dispatch()

func (*Timer) SetTimeoutIn

func (t *Timer) SetTimeoutIn(duration time.Duration)

SetTimeoutIn will set the timer to fire the handler in [duration]

func (*Timer) Stop

func (t *Timer) Stop()

Stop this timer from executing any more.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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