timer

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 License: MIT Imports: 5 Imported by: 0

README

Timer

Go Reference

The timer package provides a simple way to schedule and execute functions at specified intervals.

Installation

To use this package in your Go project, you can install it using go get:

go get github.com/gmodx/timer

Usage

Here's a basic example of how to use the timer package to schedule and execute functions at specified intervals:

Tick

The Tick function schedules a job function to be executed repeatedly with a specified delay and interval. It takes the following parameters:

  • delay: Initial delay before starting the job execution.
  • interval: Time interval between consecutive executions of the job function.
  • jobFunc: The function to be executed as a job.
  • jobErrCallback: A callback function that handles errors encountered during job execution.
  • params: Optional parameters to be passed to the job function.
func main() {
    err := timer.Tick(
        2 * time.Second, // Initial delay of 2 seconds
        1 * time.Second, // Execute the job every 1 second
        myJobFunction,   // The job function to be executed
        errorHandler,    // Function to handle job execution errors
        "param1",        // Optional parameters for the job function
        42,
    )
    if err != nil {
        fmt.Println("Error:", err)
    }

    // Keep the program running to allow the scheduled jobs to execute.
    select {}
}

func myJobFunction(param1 string, param2 int) {
    // Your job logic here
}

func errorHandler(err error) {
    fmt.Println("Job error:", err)
}

Documentation

For more information and usage examples, please refer to the GoDoc documentation.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrParamsNotAdapted = errors.New("the number of params is not adapted")
	ErrNotAFunction     = errors.New("only functions can be schedule into the job queue")
)

Functions

func Tick

func Tick(delay time.Duration, d time.Duration, jobFunc interface{}, jobErrCallback func(error), params ...interface{}) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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