{"id":16440270,"url":"https://github.com/soypat/schedule","last_synced_at":"2025-07-30T21:36:31.904Z","repository":{"id":194145658,"uuid":"690307014","full_name":"soypat/schedule","owner":"soypat","description":"Action scheduling using event loops.","archived":false,"fork":false,"pushed_at":"2023-10-08T21:13:36.000Z","size":47,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-08T12:40:42.561Z","etag":null,"topics":[],"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/soypat.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":"2023-09-12T00:21:38.000Z","updated_at":"2024-02-12T13:17:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"2d2ae5f0-5a69-4590-a84e-c83ec4b97c13","html_url":"https://github.com/soypat/schedule","commit_stats":null,"previous_names":["soypat/schedule"],"tags_count":0,"template":false,"template_full_name":"soypat/go-module-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soypat%2Fschedule","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soypat%2Fschedule/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soypat%2Fschedule/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soypat%2Fschedule/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/soypat","download_url":"https://codeload.github.com/soypat/schedule/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240766672,"owners_count":19854114,"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":[],"created_at":"2024-10-11T09:11:41.087Z","updated_at":"2025-02-25T23:45:34.727Z","avatar_url":"https://github.com/soypat.png","language":"Go","funding_links":[],"categories":["Embedded Systems"],"sub_categories":["General use"],"readme":"# schedule\n[![go.dev reference](https://pkg.go.dev/badge/github.com/soypat/schedule)](https://pkg.go.dev/github.com/soypat/schedule)\n[![Go Report Card](https://goreportcard.com/badge/github.com/soypat/schedule)](https://goreportcard.com/report/github.com/soypat/schedule)\n[![codecov](https://codecov.io/gh/soypat/schedule/branch/main/graph/badge.svg)](https://codecov.io/gh/soypat/schedule)\n[![Go](https://github.com/soypat/schedule/actions/workflows/go.yml/badge.svg)](https://github.com/soypat/schedule/actions/workflows/go.yml)\n[![sourcegraph](https://sourcegraph.com/github.com/soypat/schedule/-/badge.svg)](https://sourcegraph.com/github.com/soypat/schedule?badge)\n\n\nAction scheduling using event loops.\n\nThe basic building unit of schedules is the `Group` interface.\n\n\n```go\ntype Group interface {\n\t// Begins sets the start time of the group. It must be called before ScheduleNext.\n\t// It should reset internal state of the Group so that Group can be reused.\n\tBegins(time.Time)\n\t// ScheduleNext returns the next action when `ok` is true \n\t// and returns the action value v. \n\t// When ok=false and next=0 the Group is done.\n\tScheduleNext(time.Time) (v any, ok bool, next time.Duration, err error)\n}\n```\n\nA more complete interface could be:\n```go\ntype GroupFull interface {\n\tGroup\n\t// Start time returns the time the group was started at.\n\tStartTime() time.Time\n\t// Durations returns how long a single iteration lasts.\n\tDuration() time.Duration\n\t// Amount of times group will run. -1 for infinite iterations.\n\tIterations() int\n}\n```\n\n## Example\nThe example below demonstrates a group scheduled to add values to\nsum over the course of 1.5 seconds.\n\n```go\n\t// g is a Group with an integer value type.\n\tvar sum int\n\tconst resolution = time.Second/6\n\tstart := time.Now()\n\tg.Begins(start)\n\tfor {\n\t\tv, ok, next, err := g.ScheduleNext(time.Now())\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\n\t\tdone := !ok \u0026\u0026 next == 0\n\t\tif done {\n\t\t\tbreak\n\t\t} else if !ok {\n\t\t\tcontinue\n\t\t}\n\t\tsum += v\n\t\tfmt.Println(\"added\", v, \"to sum\", sum)\n\t\ttime.Sleep(resolution)\n\t}\n\tfmt.Println(\"done!\", time.Since(start))\n```\n\nOutputs:\n```\nadded 20 to sum 20\nadded 30 to sum 50\nadded 50 to sum 100\ndone! 1.5s\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoypat%2Fschedule","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoypat%2Fschedule","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoypat%2Fschedule/lists"}