landonia / goat

A go lang asynchronous ticker that will wrap a function on a ticker execution that can be controlled and shutdown easily

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

goat

A simple wrapper for creating a ticker execution of a function.

Overview

Goat provides the core for/select wrapper that is used to safely execute within a go routine using a ticker to signal execution of a function. The function provided will be executed at the ticker duration. A goat can be shutdown cleanly. A Goat can be reused - if it has been shutdown it can be started again without creating a new Goat.

Maturity

Ready to go and is used in production

Installation

simply run go get github.com/landonia/goat

Use as Library

	package main

	import (
  		"github.com/landonia/goat"
  	)

  	func main() {
  		// Create a new goat
  		g := goat.New(time.Minute,
         		func() {
           			fmt.Println("Executed")
         		},
       		)

       		// Start the execution
       		err := g.Start()
       		if err != nil {
       			// It means that it has already been started
         		fmt.Println("Already started")
       		}

       		// Do work
       		...

       		// Ready to shutdown
       		err = g.Stop()
       		if err != nil {
        		// It means that it was not running
         		fmt.Println("Not started")
       		}
       	}

Example

simply run go run github/landonia/goat/cmd/example.go

About

goat was written by Landon Wainwright | GitHub.

Follow me on Twitter @landoman!

About

A go lang asynchronous ticker that will wrap a function on a ticker execution that can be controlled and shutdown easily


Languages

Language:Go 100.0%