Documentation ¶
Overview ¶
delayqueue 是一款基于Golang开发的高性能延时队列
使用示例:
package main import ( "fmt" "time" "github.com/cfanbo/delayqueue" ) func consume(entry delayqueue.Entry) { fmt.Println("当前:", time.Now().Format("2006-01-02 15:04:05")) fmt.Println("消费:", entry.ConsumeTime().Format("2006-01-02 15:04:05")) fmt.Println("消费内容", entry.Body()) fmt.Println("=======================") } func main() { // 分钟级别 delayqueue.New(delayqueue.WithFrequency(time.Minute)) q := delayqueue.New() q.Put(time.Now().Add(time.Second*2), "2秒后") q.Put(time.Now().Add(time.Second*15), "15秒后") q.Put(time.Now().Add(time.Second*8), "8秒后") q.Put(time.Now().Add(time.Second*43), "43秒后") q.Put(time.Now().Add(time.Second*50), "50秒后") q.Put(time.Now().Add(time.Second*28), "28秒后") ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) defer cancel() q.Run(ctx, consume) }
Index ¶
Constants ¶
View Source
const (
// SlotsNum 队列总的slot数,每1秒移动一个slot
SlotsNum = 3600
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Elements ¶
type Elements struct {
// contains filtered or unexported fields
}
Elements 队列slot 为Element元素的集合
type Option ¶
type Option func(*Options)
func WithFrequency ¶
WithFrequency 移动slot的频率,默认情况下每秒移动一个slot
Click to show internal directories.
Click to hide internal directories.