MCPcopy
hub / github.com/go-co-op/gocron / ExampleWithClock

Function ExampleWithClock

example_test.go:868–894  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

866}
867
868func ExampleWithClock() {
869 fakeClock := clockwork.NewFakeClock()
870 s, _ := gocron.NewScheduler(
871 gocron.WithClock(fakeClock),
872 )
873 var wg sync.WaitGroup
874 wg.Add(1)
875 _, _ = s.NewJob(
876 gocron.DurationJob(
877 time.Second*5,
878 ),
879 gocron.NewTask(
880 func(one string, two int) {
881 fmt.Printf("%s, %d\n", one, two)
882 wg.Done()
883 },
884 "one", 2,
885 ),
886 )
887 s.Start()
888 _ = fakeClock.BlockUntilContext(context.Background(), 1)
889 fakeClock.Advance(time.Second * 5)
890 wg.Wait()
891 _ = s.StopJobs()
892 // Output:
893 // one, 2
894}
895
896func ExampleWithContext() {
897 s, _ := gocron.NewScheduler()

Callers

nothing calls this directly

Calls 6

NewJobMethod · 0.95
StartMethod · 0.95
StopJobsMethod · 0.95
AddMethod · 0.80
DoneMethod · 0.80
WaitMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…