Added ability to run & schedule tasks on a period
This commit is contained in:
18
scheduled/scheduled.go
Normal file
18
scheduled/scheduled.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package scheduled
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Scheduled func() (string, time.Duration)
|
||||
|
||||
func Schedule(f Scheduled) {
|
||||
print, wait := f()
|
||||
fmt.Println(print)
|
||||
|
||||
go func(w time.Duration) {
|
||||
time.Sleep(w)
|
||||
Schedule(f)
|
||||
}(wait)
|
||||
}
|
||||
Reference in New Issue
Block a user