Documentation ¶
Overview ¶
Package ticker provides ticker functionality as a module.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrMissingWithInterval = fmt.Errorf("ticker.Ticker missing WithInterval option") ErrMissingWithFunc = fmt.Errorf("ticker.Ticker missing WithFunc option") )
Functions ¶
This section is empty.
Types ¶
type Opt ¶
func WithInterval ¶
type Ticker ¶
type Ticker struct {
// contains filtered or unexported fields
}
func New ¶
New creates ticker with given options. WithInterval and WithFunc options are mandatory.
Example ¶
package main import ( "errors" "fmt" "log/slog" "time" "github.com/elisasre/go-common/v2/service" "github.com/elisasre/go-common/v2/service/module/ticker" ) func main() { t := ticker.New( ticker.WithInterval(time.Second), ticker.WithFunc(func() error { slog.Info("Hello from ticker") return errors.New("ticker error") }), ) err := service.Run(service.Modules{t}) if err != nil { fmt.Println(err) } }
Output: 1 error occurred: * failed to run module ticker.Ticker: ticker error
Click to show internal directories.
Click to hide internal directories.