MCPcopy Index your code
hub / github.com/beevik/timerqueue / ExampleQueue

Function ExampleQueue

example_test.go:18–44  ·  view source on GitHub ↗

Schedule several events with a timerqueue, and dispatch them by calling Advance.

()

Source from the content-addressed store, hash-verified

16// Schedule several events with a timerqueue, and dispatch
17// them by calling Advance.
18func ExampleQueue() {
19 queue := timerqueue.New()
20
21 // Schedule an event each day from Jan 1 to Jan 7, 2015.
22 tm := time.Date(2015, 1, 1, 0, 0, 0, 0, time.UTC)
23 for i := 1; i <= 7; i++ {
24 queue.Schedule(event(i), tm)
25 tm = tm.Add(24 * time.Hour)
26 }
27
28 fmt.Println("Advancing to Jan 4...")
29 queue.Advance(time.Date(2015, 1, 4, 0, 0, 0, 0, time.UTC))
30
31 fmt.Println("Advancing to Jan 10...")
32 queue.Advance(time.Date(2015, 1, 10, 0, 0, 0, 0, time.UTC))
33
34 // Output:
35 // Advancing to Jan 4...
36 // Event 1 executed at 2015-01-01 00:00:00 +0000 UTC
37 // Event 2 executed at 2015-01-02 00:00:00 +0000 UTC
38 // Event 3 executed at 2015-01-03 00:00:00 +0000 UTC
39 // Event 4 executed at 2015-01-04 00:00:00 +0000 UTC
40 // Advancing to Jan 10...
41 // Event 5 executed at 2015-01-05 00:00:00 +0000 UTC
42 // Event 6 executed at 2015-01-06 00:00:00 +0000 UTC
43 // Event 7 executed at 2015-01-07 00:00:00 +0000 UTC
44}

Callers

nothing calls this directly

Calls 4

NewFunction · 0.92
eventTypeAlias · 0.85
ScheduleMethod · 0.80
AdvanceMethod · 0.80

Tested by

no test coverage detected