toolsync

package
v0.0.0-...-56972d6 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

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函数会阻塞

func (*ConcurrentControl[T]) Close

func (s *ConcurrentControl[T]) Close()

Close 关闭实例

func (*ConcurrentControl[T]) Wait

func (s *ConcurrentControl[T]) Wait()

Wait 等待所有任务完成

type Map

type Map[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Map sync.Map 范型版

func (*Map[K, V]) CompareAndDelete

func (m *Map[K, V]) CompareAndDelete(key K, old V) (deleted bool)

CompareAndDelete 如果键的值等于旧值,则删除该项。 旧值必须是可比较的类型。 如果映射中没有键的当前值,则CompareAndDelete 返回false(即使旧值是nil接口值)。

func (*Map[K, V]) CompareAndSwap

func (m *Map[K, V]) CompareAndSwap(key K, old, new V) bool

func (*Map[K, V]) Delete

func (m *Map[K, V]) Delete(key K)

func (*Map[K, V]) Load

func (m *Map[K, V]) Load(key K) (value V, ok bool)

func (*Map[K, V]) LoadAndDelete

func (m *Map[K, V]) LoadAndDelete(key K) (value V, loaded bool)

LoadAndDelete 删除键的值,返回以前的值(如果有的话)。 加载的结果报告key是否存在。

func (*Map[K, V]) LoadOrStore

func (m *Map[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)

LoadOrStore 返回key的现有值(如果存在)。 否则,它将存储并返回给定的值。 如果值已加载,则加载的结果为true,如果存储,则为false。

func (*Map[K, V]) Range

func (m *Map[K, V]) Range(f func(key K, value V) bool)

func (*Map[K, V]) Store

func (m *Map[K, V]) Store(key K, value V)

func (*Map[K, V]) Swap

func (m *Map[K, V]) Swap(key K, value V) (previous V, loaded bool)

Swap 将值交换为键,并返回以前的值(如果有)。 loaded结果报告key是否存在。

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分钟, 此函数能保证脚本在同一时间只有一个进程在执行

type WaitGroup

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

sync.WaitGroup 虽然可以并发控制但是,自己本身不是并发安全的,并发add wait就会出现数据竞争

func (*WaitGroup) Add

func (s *WaitGroup) Add(delta int)

func (*WaitGroup) Done

func (s *WaitGroup) Done()

func (*WaitGroup) Wait

func (s *WaitGroup) Wait()

Jump to

Keyboard shortcuts

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