Skip to content

Package retrygroup provides synchronization, Context cancelation for groups of retry goroutines working on subtasks of a common task.

Notifications You must be signed in to change notification settings

Code-Hex/retrygroup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

retrygroup

GoDoc
Package retrygroup provides synchronization, Context cancelation for groups of retry goroutines working on subtasks of a common task.

Synopsis

package main

import (
	"context"
	"errors"
	"fmt"
	"time"

	"github.com/Code-Hex/retrygroup"
)

func main() {
	ctx, cancel := context.WithCancel(context.Background())
	g, _ := retrygroup.WithContext(ctx)
	g.EnableBackoff()

	go func() {
		<-time.After(16 * time.Second)
		if cancel != nil {
			fmt.Println("Finish!!")
			cancel()
		}
	}()

	g.RetryGo(3, func(i int) error {
		fmt.Printf("Hello: %d\n", i)
		return errors.New("Try error")
	})

	g.RetryGo(-1, func(i int) error {
		fmt.Println("Never!!")
		return errors.New("Try never error")
	})

	g.Wait()
}

See eg

About

Package retrygroup provides synchronization, Context cancelation for groups of retry goroutines working on subtasks of a common task.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages