commonutil

package
v0.0.0-...-a6492d2 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2022 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClosing  = errors.New("closing")
	ErrExist    = errors.New("exist")
	ErrNotExist = errors.New("not exist")
)
View Source
var (
	ErrCallbackNil   = errors.New("trigger: callback nil")
	ErrCallbackExist = errors.New("trigger: callback exist")
	ErrEventIllegal  = errors.New("trigger: event error")
)

Functions

func LogErrFunc

func LogErrFunc(err error)

func SequenceTickerLoop

func SequenceTickerLoop(ctx context.Context, errFn ErrFunc, duration time.Duration, exitMsg string, fn func(ctx context.Context) error)

func SleepCanClose

func SleepCanClose(sleepTime time.Duration, closeCh chan struct{})

func TickerLoop

func TickerLoop(ctx context.Context, errFn ErrFunc, duration time.Duration, fn func(ctx context.Context) error)

Types

type ErrFunc

type ErrFunc func(err error)

type GoroutineStopper

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

GoroutineStopper 提出container和shard的公共属性 抽象数据结构,也会引入数据结构之间的耦合

func (*GoroutineStopper) Close

func (stopper *GoroutineStopper) Close()

func (*GoroutineStopper) Wrap

func (stopper *GoroutineStopper) Wrap(fn StopableFunc)

type Item

type Item struct {
	Value    string // The value of the item; arbitrary.
	Priority int64  // The priority of the item in the queue.
	// The index is needed by update and is maintained by the heap.Interface methods.
	Index int // The index of the item in the heap.
}

An Item is something we manage in a priority queue.

func (*Item) String

func (i *Item) String() string

type PriorityQueue

type PriorityQueue []*Item

A PriorityQueue implements heap.Interface and holds Items.

func (PriorityQueue) Len

func (pq PriorityQueue) Len() int

func (PriorityQueue) Less

func (pq PriorityQueue) Less(i, j int) bool

func (*PriorityQueue) Pop

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

func (*PriorityQueue) Push

func (pq *PriorityQueue) Push(x interface{})

func (PriorityQueue) Swap

func (pq PriorityQueue) Swap(i, j int)

type StopableFunc

type StopableFunc func(ctx context.Context)

type Trigger

type Trigger interface {
	Register(key string, callback TriggerCallback) error
	Put(event *TriggerEvent) error
	ForEach(visitor func(it interface{}) error) error
	Close()
}

func NewTrigger

func NewTrigger(opts ...TriggerOption) (Trigger, error)

type TriggerCallback

type TriggerCallback func(key string, value interface{}) error

TriggerCallback 把event的value给到调用方

type TriggerEvent

type TriggerEvent struct {
	Key   string
	Value interface{}
}

type TriggerOption

type TriggerOption func(options *triggerOptions)

func WithWorkerSize

func WithWorkerSize(v int) TriggerOption

Jump to

Keyboard shortcuts

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