Documentation
¶
Overview ¶
concurrent 主要提供 3 个函数 GoRun,异步执行函数 Wait,等待所有任务执行完毕 UnsafeWaitWithContext,包含超时机制的等待所有任务执行完毕
Index ¶
- Variables
- func DefaultTimer(ctx context.Context, every time.Duration, fn func())
- func GoSafe(fn func())
- func Timer(ctx context.Context, first, every time.Duration, fn func())
- type Cacher
- type DefaultTracer
- type G
- type Map
- func (m *Map[K, V]) Clear()
- func (m *Map[K, V]) CompareAndDelete(key K, old V) (deleted bool)
- func (m *Map[K, V]) CompareAndSwap(key K, old, ne V) bool
- func (m *Map[K, V]) Delete(key K)
- func (m *Map[K, V]) Keys() []K
- func (m *Map[K, V]) Len() int
- 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]) Values() []V
- type TTLCache
- type TTLMap
- func (c *TTLMap[K, V]) Clear()
- func (c *TTLMap[K, V]) Delete(key K)
- func (c *TTLMap[K, V]) Dispose()
- func (c *TTLMap[K, V]) Len() int
- func (c *TTLMap[K, V]) Load(key K) (V, bool)
- func (c *TTLMap[K, V]) LoadOrStore(key K, value V, ttl time.Duration) (V, bool)
- func (c *TTLMap[K, V]) Range(fn func(key K, value V) bool)
- func (c *TTLMap[K, V]) SetTickerCleanup(interval time.Duration) *TTLMap[K, V]
- func (c *TTLMap[K, V]) Store(key K, value V, ttl time.Duration)
- func (c *TTLMap[K, V]) SwichFixedTimeClear(afterFn func() time.Duration) *TTLMap[K, V]
- type Tracer
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrCacheNotFound = errors.New("cache not found")
ErrCacheNotFound 缓存未找到错误
Functions ¶
func DefaultTimer ¶
DefaultTimer 首次是 3 秒后执行,每隔 every 执行一次
Types ¶
type Cacher ¶ added in v1.2.5
type Cacher interface {
Set(context.Context, string, any)
Del(context.Context, string)
Get(context.Context, string, any) error
SetNX(context.Context, string, any)
}
Cacher 缓存接口
type DefaultTracer ¶
type DefaultTracer struct{}
func (DefaultTracer) Error ¶
func (DefaultTracer) Error(msg string, args ...any)
type G ¶
type G struct {
// contains filtered or unexported fields
}
func (*G) UnsafeWaitWithContext ¶
UnsafeWaitWithContext wait 会一直等,此函数会有个超时限制。
type Map ¶
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
func (*Map[K, V]) CompareAndDelete ¶
CompareAndDelete 比较并删除键值对
func (*Map[K, V]) CompareAndSwap ¶
CompareAndSwap 比较并交换值
func (*Map[K, V]) LoadAndDelete ¶
LoadAndDelete 获取并删除键值对
func (*Map[K, V]) LoadOrStore ¶
LoadOrStore 获取或存储键值对
type TTLCache ¶ added in v1.2.5
TTLCache 不使用泛型,是考虑到使用 redis 时,也没办法用泛型 为了统一和代码简洁性,故而使用 any,而非泛型
func NewTTLCache ¶ added in v1.2.5
type TTLMap ¶
type TTLMap[K comparable, V any] struct { // contains filtered or unexported fields }
TTLMap 带有过期时间的 map
func NewTTLMap ¶
func NewTTLMap[K comparable, V any]() *TTLMap[K, V]
NewTTLMap 提供默认的过期删除 也可以使用 SwichFixedTimeCleanup 开启定时清空
func (*TTLMap[K, V]) LoadOrStore ¶
LoadOrStore 第二个参数,true:获取 load 的数据; false:刚存储的数据
func (*TTLMap[K, V]) SetTickerCleanup ¶ added in v1.3.11
SetTickerCleanup 设置定时清除,传 0 表示每 1 秒检测一次,interval 表示检测间隔时间
Click to show internal directories.
Click to hide internal directories.