utils

package
v0.0.0-...-a3e1a49 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrScheduleTimeout = fmt.Errorf("schedule error: timed out")

ErrScheduleTimeout returned by Pool to indicate that there no free goroutines during some period of time.

Functions

func IsTTY

func IsTTY() bool

IsTTY returns true if program is running with TTY

func Keys

func Keys[T any](val map[string]T) []string

func NextRetry

func NextRetry(step int) time.Duration

NextRetry returns a cooldown duration before next attempt using a simple exponential backoff

func OpenFileLimit

func OpenFileLimit() (limitStr string)

OpenFileLimit returns a string displaying the current open file limit for the process or unknown if it's not possible to detect it

func ToJSON

func ToJSON[T any](val T) []byte

Types

type GoPool

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

GoPool contains logic of goroutine reuse. Copied from https://github.com/gobwas/ws-examples/blob/master/src/gopool/pool.go

func AllPools

func AllPools() []*GoPool

Return all active pools

func NewGoPool

func NewGoPool(name string, size int) *GoPool

NewGoPool creates new goroutine pool with given size. Start size defaults to 20% of the max size but not greater than 1024. Queue size defaults to 50% of the max size.

func (*GoPool) Name

func (p *GoPool) Name() string

func (*GoPool) Schedule

func (p *GoPool) Schedule(task func())

Schedule schedules task to be executed over pool's workers.

func (*GoPool) ScheduleTimeout

func (p *GoPool) ScheduleTimeout(timeout time.Duration, task func()) error

ScheduleTimeout schedules task to be executed over pool's workers. It returns ErrScheduleTimeout when no free workers met during given timeout.

func (*GoPool) Size

func (p *GoPool) Size() int

type GracefulSignals

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

The struct implementing logic for graceful shutdown in response to OS signals.

func NewGracefulSignals

func NewGracefulSignals(timeout time.Duration) *GracefulSignals

Create new GracefulSignals struct.

func (*GracefulSignals) Handle

func (s *GracefulSignals) Handle(handler signalHandler)

func (*GracefulSignals) HandleForceTerminate

func (s *GracefulSignals) HandleForceTerminate(handler func())

func (*GracefulSignals) Listen

func (s *GracefulSignals) Listen()

type MessageVerifier

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

func NewMessageVerifier

func NewMessageVerifier(key string) *MessageVerifier

func (*MessageVerifier) Generate

func (m *MessageVerifier) Generate(payload interface{}) (string, error)

func (*MessageVerifier) Sign

func (m *MessageVerifier) Sign(payload []byte) ([]byte, error)

func (*MessageVerifier) Verified

func (m *MessageVerifier) Verified(msg string) (interface{}, error)

func (*MessageVerifier) VerifySignature

func (m *MessageVerifier) VerifySignature(payload []byte, digest []byte) bool

type PriorityQueue

type PriorityQueue[T any, P constraints.Ordered] []*PriorityQueueItem[T, P]

func NewPriorityQueue

func NewPriorityQueue[T any, P constraints.Ordered]() *PriorityQueue[T, P]

func (PriorityQueue[T, P]) Len

func (pq PriorityQueue[T, P]) Len() int

func (PriorityQueue[T, P]) Less

func (pq PriorityQueue[T, P]) Less(i, j int) bool

func (*PriorityQueue[T, P]) Peek

func (pq *PriorityQueue[T, P]) Peek() *PriorityQueueItem[T, P]

func (*PriorityQueue[T, P]) Pop

func (pq *PriorityQueue[T, P]) Pop() any

func (*PriorityQueue[T, P]) PopItem

func (pq *PriorityQueue[T, P]) PopItem() *PriorityQueueItem[T, P]

func (*PriorityQueue[T, P]) Push

func (pq *PriorityQueue[T, P]) Push(x any)

func (*PriorityQueue[T, P]) PushItem

func (pq *PriorityQueue[T, P]) PushItem(v T, priority P) *PriorityQueueItem[T, P]

func (*PriorityQueue[T, P]) Remove

func (pq *PriorityQueue[T, P]) Remove(item *PriorityQueueItem[T, P])

func (PriorityQueue[T, P]) Swap

func (pq PriorityQueue[T, P]) Swap(i, j int)

func (*PriorityQueue[T, P]) Update

func (pq *PriorityQueue[T, P]) Update(item *PriorityQueueItem[T, P], priority P)

Update modifies the priority and value of an Item in the queue.

type PriorityQueueItem

type PriorityQueueItem[T any, P constraints.Ordered] struct {
	// contains filtered or unexported fields
}

An PriorityQueueItem is something we manage in a priority queue.

func (PriorityQueueItem[T, P]) Priority

func (pq PriorityQueueItem[T, P]) Priority() P

func (PriorityQueueItem[T, P]) Value

func (pq PriorityQueueItem[T, P]) Value() T

Jump to

Keyboard shortcuts

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