{"id":16830726,"url":"https://github.com/jpillora/backoff","last_synced_at":"2025-05-14T07:08:54.078Z","repository":{"id":27960042,"uuid":"31453004","full_name":"jpillora/backoff","owner":"jpillora","description":"Simple backoff algorithm in Go (golang)","archived":false,"fork":false,"pushed_at":"2024-01-24T12:22:24.000Z","size":25,"stargazers_count":644,"open_issues_count":4,"forks_count":67,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-05-03T02:49:13.836Z","etag":null,"topics":["backoff","go","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jpillora.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-02-28T06:05:25.000Z","updated_at":"2025-04-14T15:52:56.000Z","dependencies_parsed_at":"2024-06-18T11:19:57.184Z","dependency_job_id":"a953d353-27ee-4338-a2ec-c2437c72507b","html_url":"https://github.com/jpillora/backoff","commit_stats":{"total_commits":29,"total_committers":10,"mean_commits":2.9,"dds":0.6206896551724138,"last_synced_commit":"fab01a9d9810a410d2d95a0a697f0afb604658f9"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpillora%2Fbackoff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpillora%2Fbackoff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpillora%2Fbackoff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpillora%2Fbackoff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jpillora","download_url":"https://codeload.github.com/jpillora/backoff/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254046780,"owners_count":22005662,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backoff","go","golang"],"created_at":"2024-10-13T11:40:38.291Z","updated_at":"2025-05-14T07:08:49.058Z","avatar_url":"https://github.com/jpillora.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Backoff\n\nA simple exponential backoff counter in Go (Golang)\n\n[![GoDoc](https://godoc.org/github.com/jpillora/backoff?status.svg)](https://godoc.org/github.com/jpillora/backoff)\n[![Build Status](https://github.com/jpillora/backoff/actions/workflows/build.yml/badge.svg)](https://github.com/jpillora/backoff/actions/workflows/build.yml)\n\n### Install\n\n```\n$ go get -v github.com/jpillora/backoff\n```\n\n### Usage\n\nBackoff is a `time.Duration` counter. It starts at `Min`. After every call to `Duration()` it is  multiplied by `Factor`. It is capped at `Max`. It returns to `Min` on every call to `Reset()`. `Jitter` adds randomness ([see below](#example-using-jitter)). Used in conjunction with the `time` package.\n\n---\n\n#### Simple example\n\n``` go\n\nb := \u0026backoff.Backoff{\n\t//These are the defaults\n\tMin:    100 * time.Millisecond,\n\tMax:    10 * time.Second,\n\tFactor: 2,\n\tJitter: false,\n}\n\nfmt.Printf(\"%s\\n\", b.Duration())\nfmt.Printf(\"%s\\n\", b.Duration())\nfmt.Printf(\"%s\\n\", b.Duration())\n\nfmt.Printf(\"Reset!\\n\")\nb.Reset()\n\nfmt.Printf(\"%s\\n\", b.Duration())\n```\n\n```\n100ms\n200ms\n400ms\nReset!\n100ms\n```\n\n---\n\n#### Example using `net` package\n\n``` go\nb := \u0026backoff.Backoff{\n    Max:    5 * time.Minute,\n}\n\nfor {\n\tconn, err := net.Dial(\"tcp\", \"example.com:5309\")\n\tif err != nil {\n\t\td := b.Duration()\n\t\tfmt.Printf(\"%s, reconnecting in %s\", err, d)\n\t\ttime.Sleep(d)\n\t\tcontinue\n\t}\n\t//connected\n\tb.Reset()\n\tconn.Write([]byte(\"hello world!\"))\n\t// ... Read ... Write ... etc\n\tconn.Close()\n\t//disconnected\n}\n\n```\n\n---\n\n#### Example using `Jitter`\n\nEnabling `Jitter` adds some randomization to the backoff durations. [See Amazon's writeup of performance gains using jitter](http://www.awsarchitectureblog.com/2015/03/backoff.html). Seeding is not necessary but doing so gives repeatable results.\n\n```go\nimport \"math/rand\"\n\nb := \u0026backoff.Backoff{\n\tJitter: true,\n}\n\nrand.Seed(42)\n\nfmt.Printf(\"%s\\n\", b.Duration())\nfmt.Printf(\"%s\\n\", b.Duration())\nfmt.Printf(\"%s\\n\", b.Duration())\n\nfmt.Printf(\"Reset!\\n\")\nb.Reset()\n\nfmt.Printf(\"%s\\n\", b.Duration())\nfmt.Printf(\"%s\\n\", b.Duration())\nfmt.Printf(\"%s\\n\", b.Duration())\n```\n\n```\n100ms\n106.600049ms\n281.228155ms\nReset!\n100ms\n104.381845ms\n214.957989ms\n```\n\n#### Documentation\n\nhttps://godoc.org/github.com/jpillora/backoff\n\n#### Credits\n\nForked from [some JavaScript](https://github.com/segmentio/backo) written by [@tj](https://github.com/tj)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjpillora%2Fbackoff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjpillora%2Fbackoff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjpillora%2Fbackoff/lists"}