Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.
/ timer Public archive

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

License

Notifications You must be signed in to change notification settings

gmodx/timer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages