{"id":27069482,"url":"https://github.com/tideland/go-wait","last_synced_at":"2025-04-05T21:33:45.493Z","repository":{"id":43359570,"uuid":"403090430","full_name":"tideland/go-wait","owner":"tideland","description":"Useful package for the polling of conditions in intervals, with timeouts, cancelation, and jittering. Additionally provides a throttle for event processing.","archived":false,"fork":false,"pushed_at":"2024-04-13T20:51:52.000Z","size":72,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-23T11:25:04.919Z","etag":null,"topics":["go","golang","limiting","package","polling","throttling","waiting"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tideland.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2021-09-04T15:23:16.000Z","updated_at":"2022-03-05T21:21:56.000Z","dependencies_parsed_at":"2024-04-06T22:28:53.294Z","dependency_job_id":"dded76a5-f062-4821-bc9f-ea97263ab802","html_url":"https://github.com/tideland/go-wait","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tideland%2Fgo-wait","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tideland%2Fgo-wait/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tideland%2Fgo-wait/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tideland%2Fgo-wait/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tideland","download_url":"https://codeload.github.com/tideland/go-wait/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247406076,"owners_count":20933803,"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":["go","golang","limiting","package","polling","throttling","waiting"],"created_at":"2025-04-05T21:33:16.077Z","updated_at":"2025-04-05T21:33:45.454Z","avatar_url":"https://github.com/tideland.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tideland Go Wait\n\n[![GitHub release](https://img.shields.io/github/release/tideland/go-wait.svg)](https://github.com/tideland/go-wait)\n[![GitHub license](https://img.shields.io/badge/license-New%20BSD-blue.svg)](https://raw.githubusercontent.com/tideland/go-wait/main/LICENSE)\n[![Go Module](https://img.shields.io/github/go-mod/go-version/tideland/go-wait)](https://github.com/tideland/go-wait/blob/main/go.mod)\n[![GoDoc](https://godoc.org/tideland.dev/go/actor?status.svg)](https://pkg.go.dev/mod/tideland.dev/go/wait?tab=packages)\n[![Workflow](https://github.com/tideland/go-wait/actions/workflows/build.yml/badge.svg)](https://github.com/tideland/go-wait/actions/)\n[![Go Report Card](https://goreportcard.com/badge/github.com/tideland/go-wait)](https://goreportcard.com/report/tideland.dev/go/wait)\n\n### Description\n\n**Tideland Go Wait** provides provides a flexible and controlled waiting for wanted conditions by polling. The function for testing has to be defined, different tickers for the polling can be generated for\n\n- simple constant intervals,\n- a maximum number of constant intervals,\n- a constant number of intervals with a deadline,\n- a onstant number of intervals with a timeout, and\n- jittering intervals.\n\nOwn tickers, e.g. with changing intervals, can be implemented too.\n\nAnother component of the package is the throttle, others would call it limiter. It allows the limited processing of events per second. Events are closures or functions with a defined signature. Depending on the burst size of the throttle multiple events can be processed with one call.\n\nI hope you like it. ;)\n\n### Examples\n\n#### Polling\n\nA simple check for an existing file by polling every second for maximal 30 seconds.\n\n```go\n// Tick every second for maximal 30 seconds.\nticker := wait.MakeExpiringIntervalTicker(time.Second, 30*time.Second),\n\n// Check for existence of a file.\ncontition := func() (bool, error) {\n    _, err := os.Stat(\"myfile.txt\")\n    if err != nil {\n        if os.IsNotExist(err) {\n            return false, nil\n        }\n        return false, err\n    }\n    // Found file.\n    return true, nil\n}\n\n// And now poll.\nwait.Poll(ctx, ticker, condition)\n```\n\n#### Throttling\n\nA throttled wrapper of a `http.Handler`.\n\n```go\ntype ThrottledHandler struct {\n    throttle *wait.Throttle\n    handler  http.Handler\n}\n\nfunc NewThrottledHandler(limit wait.Limit, handler http.Handler) http.Handler {\n    return \u0026ThrottledHandler{\n        throttle: wait.NewThrottle(limit, 1),\n        handler:  handler,\n    }\n}\n\nfunc (h *ThrottledHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {\n    evt := func() error {\n        h.handler.ServeHTTP(w, r)\n        return nil\n    }\n    h.throttle.Process(context.Background(), evt)\n}\n```\n\n### Contributors\n\n- Frank Mueller (https://github.com/themue / https://github.com/tideland / https://tideland.dev)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftideland%2Fgo-wait","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftideland%2Fgo-wait","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftideland%2Fgo-wait/lists"}