util

package
v2.2.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2019 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DumpHeap

func DumpHeap() (string, int)

DumpHeap uses pprof to inspect the heap

func DumpPProfStack

func DumpPProfStack() (string, int)

DumpPProfStack uses pprof to inspect goroutines

func DumpRuntimeStack

func DumpRuntimeStack() string

DumpRuntimeStack uses runtime to inspect goroutines

Types

type PriorityQueue

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

PriorityQueue uses a max heap, and provides efficient changing of priority.

func NewPriorityQueue

func NewPriorityQueue() *PriorityQueue

NewPriorityQueue .....

func (*PriorityQueue) Add

func (pq *PriorityQueue) Add(key string, priority int, value interface{}) error

Add adds an element. 'key' must be unique.

func (*PriorityQueue) CheckValidity

func (pq *PriorityQueue) CheckValidity() []string

CheckValidity should always return an empty slice -- it is just a debugging tool. If it returns a non-empty slice, then there's a bug somewhere in the heap code.

func (*PriorityQueue) DebugString

func (pq *PriorityQueue) DebugString() string

DebugString should only be used for debugging.

func (*PriorityQueue) Dump

func (pq *PriorityQueue) Dump() []map[string]interface{}

Dump should only be used for debugging.

func (*PriorityQueue) HasKey

func (pq *PriorityQueue) HasKey(key string) bool

HasKey returns whether the priority queue has the key.

func (*PriorityQueue) IsEmpty

func (pq *PriorityQueue) IsEmpty() bool

IsEmpty .....

func (*PriorityQueue) Peek

func (pq *PriorityQueue) Peek() interface{}

Peek returns the highest priority item, or nil if empty.

func (*PriorityQueue) Pop

func (pq *PriorityQueue) Pop() (interface{}, error)

Pop removes the highest priority element, returning an error if empty.

func (*PriorityQueue) Remove

func (pq *PriorityQueue) Remove(key string) (interface{}, error)

Remove removes the value associated with the key from the priority queue, returning an error if it can't be found.

func (*PriorityQueue) Set

func (pq *PriorityQueue) Set(key string, priority int) error

Set changes the priority of 'value' if it can be found, and returns an error if not.

func (*PriorityQueue) Size

func (pq *PriorityQueue) Size() int

Size returns the number of elements in the queue.

func (*PriorityQueue) Values

func (pq *PriorityQueue) Values() []interface{}

Values should only be used for debugging.

type Timer

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

Timer periodically executes `action`, waiting `delay` between invocation starts. If `action` takes longer than `delay`, invocations will be dropped. It stops when receiving an event on `stop`. It's basically a time.Ticker with additional functionality for pausing and resuming.

func NewRunningTimer

func NewRunningTimer(name string, delay time.Duration, stop <-chan struct{}, runImmediately bool, action func()) *Timer

NewRunningTimer creates a new timer which is running

func NewTimer

func NewTimer(name string, delay time.Duration, stop <-chan struct{}, action func()) *Timer

NewTimer creates a new timer which is paused

func (*Timer) Pause

func (timer *Timer) Pause() error

Pause temporarily stops the timer. It returns an error if the timer could not be paused.

func (*Timer) Resume

func (timer *Timer) Resume(runImmediately bool) error

Resume resumes the timer with the option of immediately running the action.

func (*Timer) SetDelay

func (timer *Timer) SetDelay(delay time.Duration)

SetDelay sets the delay

type TimerState

type TimerState int

TimerState describes the state of a timer

const (
	TimerStateReady         TimerState = iota
	TimerStateRunningAction TimerState = iota
	TimerStatePaused        TimerState = iota
	TimerStateStopped       TimerState = iota
)

.....

func (TimerState) String

func (state TimerState) String() string

String .....

Jump to

Keyboard shortcuts

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