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.

40 lines
1007 B

package codeforcesbot
import (
"fmt"
"time"
)
type TickerFunc func(time.Time)
func addTimer(duration time.Duration, tf TickerFunc) {
fmt.Println("add timer")
Timer := time.NewTimer(duration)
tf(<-Timer.C)
}
func addTicker(duration time.Duration, tf TickerFunc) {
fmt.Println("add ticker")
Timer := time.NewTicker(duration)
for {
tf(<-Timer.C)
fmt.Println("trigger")
}
}
func notifyTodaysContestsWrapped(t time.Time) {
fmt.Println("notify todays contests wrapped")
notifyTodaysContests(t)
addTicker(time.Hour * 24, notifyTodaysContests)
}
func InitializeTimersAndTickers() {
if time.Now().Hour() >= 8 {
year, month, day := time.Now().AddDate(0, 0, 1).Date()
go addTimer(time.Until(time.Date(year, month, day, 8, 0, 0, 0, time.Local)), notifyTodaysContestsWrapped)
} else {
year, month, day := time.Now().Date()
go addTimer(time.Until(time.Date(year, month, day, 8, 0, 0, 0, time.Local)), notifyTodaysContestsWrapped)
}
//go addTimer(time.Second * 10, notifyTodaysContests)
}