1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
package schedule_test
import (
"fmt"
"time"
"atomicgo.dev/schedule"
)
func ExampleAfter() {
task := schedule.After(5*time.Second, func() {
fmt.Println("5 seconds are over!")
})
fmt.Println("Some stuff happening...")
task.Wait()
}
func ExampleAt() {
task := schedule.At(time.Now().Add(5*time.Second), func() {
fmt.Println("5 seconds are over!")
})
fmt.Println("Some stuff happening...")
task.Wait()
}
func ExampleEvery() {
task := schedule.Every(time.Second, func() bool {
fmt.Println("1 second is over!")
return true // return false to stop the task
})
fmt.Println("Some stuff happening...")
time.Sleep(10 * time.Second)
task.Stop()
}
|