theTardigrade / golang-tasks

This package allows tasks to be set, whereby handler functions will run at given intervals.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

golang-tasks

This package allows tasks to be set, whereby handler functions will run at given intervals.

Go Reference Go Report Card

Example

package main

import (
	"fmt"
	"time"

	tasks "github.com/theTardigrade/golang-tasks"
)

func main() {
	// set up a handler function to run once every second;
	// do not call the function on initialization
	tasks.Set(time.Second, false, func(id *tasks.Identifier) {
		fmt.Println("ONE SECOND HAS PASSED")

		// stop the task after five seconds
		if id.DurationSinceSet() >= time.Second*5 {
			id.Stop()
		}
	})

	// keep the main function running
	select {}
}

Support

If you use this package, or find any value in it, please consider donating:

ko-fi

About

This package allows tasks to be set, whereby handler functions will run at given intervals.

License:GNU General Public License v2.0


Languages

Language:Go 100.0%