cronticker

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: MIT Imports: 3 Imported by: 0

README

⏰ cronticker

cronticker implements a ticker that works with crontab schedules.

🚀 Install

go get github.com/martin-viggiano/cronticker

📚 Usage

Go doc: https://pkg.go.dev/github.com/martin-viggiano/cronticker

import (
	"log"

	"github.com/martin-viggiano/cronticker"
)

func main() {
	ticker, err := cronticker.NewTicker("5 4 * * *")
	if err != nil {
		log.Fatal("failed to create ticker")
	}
	defer ticker.Stop()

	select {
	case <-ticker.C:
		log.Print("it is 04:05")
	}

	err = ticker.Reset("5 4 * * *")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ticker

type Ticker struct {
	C chan time.Time
	// contains filtered or unexported fields
}

A Ticker holds a channel that delivers “ticks” of a clock acording to a crontab schedule.

func NewTicker

func NewTicker(spec string) (*Ticker, error)

NewTicker returns a new Ticker containing a channel that will send the current time on the channel according to the crontab schedule. The crontab schedule is specified by the spec argument and will be parsed using the standard specification. Stop the ticker to release associated resources.

func NewTickerWithParser

func NewTickerWithParser(spec string, parser cron.Parser) (*Ticker, error)

NewTickerWithParser returns a new Ticker containing a channel that will send the current time on the channel accordint to the crontab schedule. The crontab schedule is specified by the spec argument and will be parsed using the provided parser. Stop the ticker to release associated resources.

func (*Ticker) Reset

func (t *Ticker) Reset(spec string) error

Reset stops a ticker and resets its crontab schedule to the specified spec. An error is returned if the crontab specification cant be pased.

func (*Ticker) Stop

func (t *Ticker) Stop()

Stop turns off a ticker. After Stop, no more ticks will be sent. Stop does not close the channel, to prevent a concurrent goroutine reading from the channel from seeing an erroneous "tick".

Jump to

Keyboard shortcuts

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