Skip to content

Latest commit

 

History

History
40 lines (27 loc) · 806 Bytes

README.md

File metadata and controls

40 lines (27 loc) · 806 Bytes

recurrent

main

A Go package to run tasks recurrently. - Inspired by the Python lib schedule

  • Parallel execution of jobs
  • Cancellation of running jobs via context

Usage

package main

import (
	"context"
	"fmt"
	"time"

	"github.com/flowck/recurrent/recurrent"
)

func main() {
	ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
	defer cancel()

	s := recurrent.New()

	s.Every(time.Second * 1).Do(func(ctx context.Context) {
		fmt.Println("--->", time.Now())
	})

	s.Every(time.Second * 2).Do(func(ctx context.Context) {
		fmt.Println("--->", time.Now())
	})

	s.Run(ctx)
}