Files
gin-gonic-prepack/scheduled/scheduled.go
2022-05-29 20:10:03 +02:00

25 lines
407 B
Go

package scheduled
import (
"fmt"
"time"
)
type Scheduled func() (string, time.Duration)
func ExecuteImmediatelyAndSchedule(f Scheduled) {
print, wait := f()
fmt.Println(print)
go ExecuteWithDelayAndSchedule(f, wait)
}
func ExecuteWithDelayAndSchedule(f Scheduled, wait time.Duration) {
time.Sleep(wait)
print, nextWait := f()
fmt.Println(print)
go ExecuteWithDelayAndSchedule(f, nextWait)
}