coroutine

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrChannelClosed = errors.New("channel closed")
	ErrBufferFull    = errors.New("buffer full")
)

Functions

func Context

func Context() context.Context

Context 获取全局顶层context

func GetContextWithCancel

func GetContextWithCancel() (context.Context, context.CancelFunc)

func Shutdown

func Shutdown()

Shutdown 关闭应用程序, 通知所有协程退出

func WaitForShutdown

func WaitForShutdown()

WaitForShutdown 阻塞等待关闭信号

Types

type Channel

type Channel[E any] struct {
	// contains filtered or unexported fields
}

func NewChannel

func NewChannel[E any](bufSize int) *Channel[E]

func (*Channel[E]) Cap

func (c *Channel[E]) Cap() int

func (*Channel[E]) Close

func (c *Channel[E]) Close()

func (*Channel[E]) Len

func (c *Channel[E]) Len() int

func (*Channel[E]) Pop

func (c *Channel[E]) Pop() (E, bool)

func (*Channel[E]) Push

func (c *Channel[E]) Push(v E) error

func (*Channel[E]) SafePush

func (c *Channel[E]) SafePush(v E, timeout time.Duration) error

SafePush 带超时的安全推送

type PeriodicOnce deprecated

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

PeriodicOnce 周期性懒加载机制

Deprecated: 推荐 RollingOnce [wangfeng on 2024/1/22 10:33]

func (*PeriodicOnce) Do

func (o *PeriodicOnce) Do(f func())

func (*PeriodicOnce) Reset

func (o *PeriodicOnce) Reset()

Reset 被动的方式重置初始化done标志

type RollingMutex deprecated

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

RollingMutex 按指定rolling策略加锁, 指定周期内只加载一次

滑动窗口锁, 窗口期内只初始化一次, 目前只支持1天切换

Deprecated: 不推荐, 建议使用 RollingOnce

func (*RollingMutex) Date

func (o *RollingMutex) Date() string

func (*RollingMutex) Do

func (o *RollingMutex) Do(f func(), today ...func() (newDate string))

func (*RollingMutex) Reset

func (o *RollingMutex) Reset()

type RollingOnce

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

RollingOnce 周期性懒加载机制

func (*RollingOnce) Close

func (o *RollingOnce) Close()

Close 资源关闭方法

func (*RollingOnce) Do

func (o *RollingOnce) Do(f func())

func (*RollingOnce) GetCurrentAnchorPoint

func (o *RollingOnce) GetCurrentAnchorPoint() int64

GetCurrentAnchorPoint 获取当前时间窗口期的锚点

func (*RollingOnce) Reset

func (o *RollingOnce) Reset()

Reset 被动的方式重置初始化done标志

func (*RollingOnce) SetOffsetForZero

func (o *RollingOnce) SetOffsetForZero(offsetMilliSeconds int64)

SetOffsetForZero 设置时间窗口变化的偏移量

为非默认9点整重置done预留的功能性方法

func (*RollingOnce) SetOffsetTime

func (o *RollingOnce) SetOffsetTime(hour, minute int)

SetOffsetTime 用小时数,分钟数设置滑动窗口的偏移量

func (*RollingOnce) WindowIsExpired

func (o *RollingOnce) WindowIsExpired() bool

WindowIsExpired 检查当前窗口期的是否过期

type RollingWaitGroup

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

RollingWaitGroup 滑动窗口n的WaitGroup

func NewRollingWaitGroup

func NewRollingWaitGroup(n int) *RollingWaitGroup

NewRollingWaitGroup initialization RollingWaitGroup struct

func (*RollingWaitGroup) Add

func (g *RollingWaitGroup) Add(delta int)

func (*RollingWaitGroup) Done

func (g *RollingWaitGroup) Done()

func (*RollingWaitGroup) Wait

func (g *RollingWaitGroup) Wait()

type SpinLock

type SpinLock uint32

SpinLock 自旋锁对象定义

func (*SpinLock) Lock

func (sl *SpinLock) Lock()

Lock 加锁

todo: 未加验证

func (*SpinLock) UnLock

func (sl *SpinLock) UnLock()

UnLock 解锁

Directories

Path Synopsis
v2
demo command

Jump to

Keyboard shortcuts

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