Skip to content

Latest commit

 

History

History
67 lines (51 loc) · 1.46 KB

README.md

File metadata and controls

67 lines (51 loc) · 1.46 KB

retry

A tiny library for retrying failing operations with Go.

License ReportCard Build Coverage GoDoc

Get

go get -u github.com/LyricTian/retry

Usage

package main

import (
	"errors"
	"fmt"
	"log"
	"time"

	"github.com/LyricTian/retry"
)

func main() {
	var (
		count int
		value string
	)

	err := retry.DoFunc(3, func() error {
		if count > 1 {
			value = "foo"
			return nil
		}
		count++
		return errors.New("not allowed")
	})

	if err != nil {
		log.Fatalln(err.Error())
	}

	fmt.Println(value)
	// Output: foo
}

MIT License

    Copyright (c) 2017 Lyric