AI写作智能体 自主规划任务,支持联网查询和网页读取,多模态高效创作各类分析报告、商业计划、营销方案、教学内容等。 广告
**jasonlvhit/gocron** 安装: ~~~ go get -u github.com/jasonlvhit/gocron ~~~ 每隔1秒执行一个任务,每隔4秒执行另一个任务: ~~~ package main import ( "fmt" "time" "github.com/jasonlvhit/gocron" ) func task() { fmt.Println("I am runnning task.", time.Now()) } func superWang() { fmt.Println("I am runnning superWang.", time.Now()) } func main() { s := gocron.NewScheduler() s.Every(1).Seconds().Do(task) s.Every(4).Seconds().Do(superWang) sc := s.Start() // keep the channel go test(s, sc) // wait <-sc // it will happens if the channel is closed } func test(s *gocron.Scheduler, sc chan bool) { time.Sleep(8 * time.Second) s.Remove(task) //remove task time.Sleep(8 * time.Second) s.Clear() fmt.Println("All task removed") close(sc) // close the channel } ~~~