Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Scheduler ¶
type Scheduler interface { Schedule(t time.Time, event, payload string) error Listen(event string, f func(payload string)) }
Scheduler defines a simple interface to schedule and listen for time-based events.
Example ¶
package main import ( "fmt" "github.com/mewil/sterling" "log" "time" ) func main() { // Create a scheduler s, _ := sterling.NewScheduler("memory://", log.Printf) done := make(chan struct{}) // Listen for events of type "send email" and process them with a callback go s.Listen("send email", func(payload string) { fmt.Println(payload) close(done) }) // Schedule events with a payload at specific times _ = s.Schedule(time.Now(), "send email", "hello world") <-done }
Output: hello world
func NewScheduler ¶
NewScheduler creates a new scheduler that users tailetc. The first argument is the same as the second argument of tailetc.New and specifies whether the data is stored in memory, on disk, or in an etcd cluster. The scheduler will log information using the function passed to logf.
Click to show internal directories.
Click to hide internal directories.