AFAIRE
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
scheduler/event.go

56 lines
1.1 KiB

/*
------------------------------------------------------------------------------------------------------------------------
####### scheduler ####### Copyright (c) 2021-2022 losyme ########################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package scheduler
import "github.com/robfig/cron/v3"
type Message struct {
Event string
Data interface{}
}
type handler struct {
onMessage OnMessage
cron *cron.Cron
}
type event struct {
name string
data interface{}
handler *handler
}
func (e *event) Run() {
e.handler.onMessage(
&Message{
Event: e.name,
Data: e.data,
},
)
}
type eStarter struct {
*event
after cron.EntryID
repeat cron.Schedule
}
func (e *eStarter) Run() {
e.event.Run()
if e.after != 0 {
e.handler.cron.Remove(e.after)
}
if e.repeat != nil {
e.handler.cron.Schedule(e.repeat, e.event)
}
}
/*
######################################################################################################## @(°_°)@ #######
*/