barrier

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append[T Comparable](slice []T, values ...T) []T

Append 渐进式扩容

func GetTopDuration

func GetTopDuration(tasks []Task) float32

GetTopDuration 获取任务列表中最高耗时任务及其耗时的功能

func GoSafe

func GoSafe(fn func())

GoSafe runs the given fn using another goroutine, recovers if fn panics.

func Guard

func Guard(lock sync.Locker, fn func())

Guard 通过互斥锁保护会被共享的资源

func NewJob

func NewJob() *job

func Recover

func Recover(cleanups ...func())

Recover is used with defer to do cleanup on panics.

func RunSafe

func RunSafe(fn func())

RunSafe runs the given fn, recovers if fn panics.

Types

type Barrier

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

func (*Barrier) Guard

func (b *Barrier) Guard(fn func())

Guard 通过互斥锁保护会被共享的资源

type Comparable

type Comparable interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | uint8 | uint32 | uint64 | ~string | ~float32 | ~float64 | struct{}
}

type HookOption

type HookOption struct {
	Current TaskHook
	Prev    TaskHook
	After   TaskHook
	Params  []interface{}
}

func WithAfter

func WithAfter(after TaskHook, params ...interface{}) HookOption

func WithCurrent

func WithCurrent(current TaskHook, params ...interface{}) HookOption

func WithPrev

func WithPrev(prev TaskHook, params ...interface{}) HookOption

type JobFunc

type JobFunc func() interface{}

type MapSet

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

func (*MapSet) Add

func (this *MapSet) Add(key interface{}) bool

func (*MapSet) Clear

func (this *MapSet) Clear()

func (*MapSet) Contains

func (this *MapSet) Contains(key interface{}) bool

func (*MapSet) Difference

func (this *MapSet) Difference(other Set) Set

func (*MapSet) Intersect

func (this *MapSet) Intersect(other Set) Set

Intersect 求交集,当数据在两个集合内都存在的时候才会生成交集

func (*MapSet) KeysStr

func (this *MapSet) KeysStr() []string

KeysStr returns string keys in s.

func (*MapSet) Remove

func (this *MapSet) Remove(key interface{}) bool

func (*MapSet) Size

func (this *MapSet) Size() int

func (*MapSet) Union

func (this *MapSet) Union(other Set) Set

func (*MapSet) Values

func (this *MapSet) Values() []interface{}

type Set

type Set interface {
	Add(interface{}) bool      //添加元素
	Remove(interface{}) bool   //删除元素
	Contains(interface{}) bool //判断是否包含元素

	Size() int             //返回集合大小
	Clear()                //清空集合
	Values() []interface{} //返回集合中所有元素的切片
	KeysStr() []string

	Union(other Set) Set      //返回另一个集合的并集
	Intersect(other Set) Set  //返回另一个集合的交集
	Difference(other Set) Set //返回另一个集合的差集
}

func NewSet

func NewSet() Set

type SetT

type SetT[T Comparable] interface {
	Add(T) bool      //添加元素
	Remove(T) bool   //删除元素
	Contains(T) bool //判断是否包含元素

	Size() int   //返回集合大小
	Clear()      //清空集合
	Values() []T //返回集合中所有元素的切片
	ValueList() []T

	Union(other SetT[T]) SetT[T]      //返回另一个集合的并集
	Intersect(other SetT[T]) SetT[T]  //返回另一个集合的交集
	Difference(other SetT[T]) SetT[T] //返回另一个集合的差集
}

func NewSetT

func NewSetT[T Comparable]() SetT[T]

type SingleFlight

type SingleFlight interface {
	Do(key string, fn func() (interface{}, error)) (interface{}, error)
	DoEx(key string, fn func() (interface{}, error)) (interface{}, bool, error)
}

SingleFlight 并发任务抽象

func NewFlightGroup

func NewFlightGroup() SingleFlight

type Slice

type Slice[T Comparable] struct {
	// contains filtered or unexported fields
}

func NewSlice

func NewSlice[T Comparable](slice []T) *Slice[T]

func (*Slice[T]) Append

func (s *Slice[T]) Append(value T) []T

Append 尾插

func (*Slice[T]) Clear

func (s *Slice[T]) Clear()

func (*Slice[T]) IndexAdd

func (s *Slice[T]) IndexAdd(index int, value T) []T

IndexAdd 基于索引添加

func (*Slice[T]) IndexEdit

func (s *Slice[T]) IndexEdit(index int, value T) []T

IndexEdit 基于索引编辑

func (*Slice[T]) IndexRemove

func (s *Slice[T]) IndexRemove(index int) []T

IndexRemove 基于索引删除

func (*Slice[T]) Prepend

func (s *Slice[T]) Prepend(value T) []T

Prepend 头插

func (*Slice[T]) QueryIndex

func (s *Slice[T]) QueryIndex(value T) int

QueryIndex 获取指定值的索引

func (*Slice[T]) QueryValue

func (s *Slice[T]) QueryValue(index int) interface{}

QueryValue 获取指定索引的值

type Task

type Task struct {
	Drop        bool
	Duration    time.Duration
	Description string
}

func TopK

func TopK(all []Task, k int) []Task

TopK 返回包含耗时最高的k个任务的切片

type TaskHook

type TaskHook func(...interface{})

type TopicInter

type TopicInter interface {
	AddTopic(string, HookOption) *topicTask
	PrevHandle(string, HookOption) *topicTask
	AfterHandle(string, HookOption) *topicTask
	DoAll()
}

func Topic

func Topic() TopicInter

Jump to

Keyboard shortcuts

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