ticker

package
v1.4.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 15, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

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

type Opt func(*Ticker) error

func WithFunc

func WithFunc(fn func() error) Opt

func WithInterval

func WithInterval(d time.Duration) Opt

type Ticker

type Ticker struct {
	// contains filtered or unexported fields
}

func New

func New(opts ...Opt) *Ticker

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/service"
	"github.com/elisasre/go-common/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

func (*Ticker) Init

func (t *Ticker) Init() error

func (*Ticker) Name

func (t *Ticker) Name() string

func (*Ticker) Run

func (t *Ticker) Run() error

func (*Ticker) Stop

func (t *Ticker) Stop() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL