coroutine

package
v1.22.10 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidOffset = errors.New("offset must be in [0, 86400000)")
	ErrNilFunction   = errors.New("function cannot be nil")
)

Functions

This section is empty.

Types

type RollingOnce

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

RollingOnce 实现基于时间窗口的周期性任务懒加载 默认每天在指定偏移时间(如9:00)重置状态,允许再次执行任务

func NewRollingOnce

func NewRollingOnce(windowMs, offsetMs int64, task func()) (*RollingOnce, error)

NewRollingOnce 创建新的RollingOnce实例 参数说明:

windowMs - 窗口持续时间(毫秒),建议 >= 1000
offsetMs - 每日偏移量(毫秒),范围 [0, 86400000)
task     - 要执行的任务函数

func NewRollingOnceWithHourAndMinute added in v1.22.9

func NewRollingOnceWithHourAndMinute(hour, minute int, task func()) (*RollingOnce, error)

NewRollingOnceWithHourAndMinute 创建指定时分的每日初始化RollingOnce实例

func (*RollingOnce) AdjustOffset

func (o *RollingOnce) AdjustOffset(newOffsetMs int64) error

AdjustOffset 动态调整时间偏移量(线程安全)

func (*RollingOnce) Close

func (o *RollingOnce) Close()

Close 安全停止后台监听

func (*RollingOnce) Do

func (o *RollingOnce) Do()

Do 执行任务(仅在当前时间窗口内首次调用有效)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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