Documentation
¶
Index ¶
- type ConcurrentControl
- type Map
- func (m *Map[K, V]) CompareAndDelete(key K, old V) (deleted bool)
- func (m *Map[K, V]) CompareAndSwap(key K, old, new V) bool
- func (m *Map[K, V]) Delete(key K)
- func (m *Map[K, V]) Keys() []K
- func (m *Map[K, V]) Load(key K) (value V, ok bool)
- func (m *Map[K, V]) LoadAndDelete(key K) (value V, loaded bool)
- func (m *Map[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)
- func (m *Map[K, V]) Range(f func(key K, value V) bool)
- func (m *Map[K, V]) Store(key K, value V)
- func (m *Map[K, V]) Swap(key K, value V) (previous V, loaded bool)
- func (m *Map[K, V]) ToMap() map[K]V
- func (m *Map[K, V]) Values() []V
- type SyncLinear
- type WaitGroup
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConcurrentControl ¶
type ConcurrentControl[T any] struct { // contains filtered or unexported fields }
ConcurrentControl 并发控制 使用场景 如:循环处理1000条数据,最大并发100个,并等待所有任务处理完成。
func NewConcurrencyControl ¶
func NewConcurrencyControl[T any](Concurrent int) *ConcurrentControl[T]
Deprecated 推荐使用 "github.com/sourcegraph/conc/pool" NewConcurrencyControl 初始化并发控制实例 Concurrent:并发数
func (*ConcurrentControl[T]) Add ¶
func (s *ConcurrentControl[T]) Add(param T, f func(data T))
Add 添加任务 param是传给回调函数的参数,data==param add任务个数等于Concurrent时,add函数会阻塞
type Map ¶
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
Map sync.Map 范型版
func (*Map[K, V]) CompareAndDelete ¶
CompareAndDelete 如果键的值等于旧值,则删除该项。 旧值必须是可比较的类型。 如果映射中没有键的当前值,则CompareAndDelete 返回false(即使旧值是nil接口值)。
func (*Map[K, V]) CompareAndSwap ¶
func (*Map[K, V]) LoadAndDelete ¶
LoadAndDelete 删除键的值,返回以前的值(如果有的话)。 加载的结果报告key是否存在。
func (*Map[K, V]) LoadOrStore ¶
LoadOrStore 如果key对应的值存在,则返回该已有的值。 否则,它将存储并返回给定的值。 如果是加载到的值,loaded结果为true;如果是存储的值,loaded结果为false。
type SyncLinear ¶
type SyncLinear struct {
// contains filtered or unexported fields
}
SyncLinear 线性执行一个函数
func (*SyncLinear) Do ¶
func (s *SyncLinear) Do(f func())
Do 新开一个 goroutine 执行函数f, 并保证函数f 在同一时刻只有一个并发在执行 使用场景 如:在linux cround 每分钟中执行一个脚本,脚本执行一次需要2分钟, 此函数能保证脚本在同一时间只有一个进程在执行