{"id":27424636,"url":"https://github.com/ktsivkov/servantgo","last_synced_at":"2025-04-14T11:51:00.574Z","repository":{"id":143198334,"uuid":"614882523","full_name":"ktsivkov/servantgo","owner":"ktsivkov","description":"ServantGo provides a simple and idiomatic way to merge tasks of the same type that happens to run simultaneously.","archived":false,"fork":false,"pushed_at":"2023-04-08T16:26:06.000Z","size":6,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-06-20T10:13:52.972Z","etag":null,"topics":["go","golang","performance-optimization","performance-optimizations","task-manager-golang","task-scheduler","task-scheduling"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/ktsivkov/servantgo","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/ktsivkov.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-03-16T14:07:10.000Z","updated_at":"2023-12-05T05:43:27.000Z","dependencies_parsed_at":"2023-05-23T19:00:31.494Z","dependency_job_id":null,"html_url":"https://github.com/ktsivkov/servantgo","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsivkov%2Fservantgo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsivkov%2Fservantgo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsivkov%2Fservantgo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsivkov%2Fservantgo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ktsivkov","download_url":"https://codeload.github.com/ktsivkov/servantgo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248877985,"owners_count":21176239,"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","performance-optimization","performance-optimizations","task-manager-golang","task-scheduler","task-scheduling"],"created_at":"2025-04-14T11:51:00.006Z","updated_at":"2025-04-14T11:51:00.566Z","avatar_url":"https://github.com/ktsivkov.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ServantGo\nTask execution and merging library\n\n**ServantGo** provides a simple and idiomatic way to merge tasks of the same type that happens to run simultaneously.\n\n## Installation + Example\n\nRun `go get github.com/ktsivkov/servantgo`\n\nCreate a struct for your task, and ensure that it implements the `Task` interface.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"sync\"\n\t\"time\"\n\n\t\"github.com/ktsivkov/servantgo\"\n)\n\ntype taskMock struct {\n\tresult time.Time\n}\n\nfunc (t *taskMock) Hash() servantgo.Hash {\n\treturn \"test\"\n}\n\nfunc (t *taskMock) Exec() {\n\ttime.Sleep(time.Second * 5)\n\tt.result = time.Now()\n}\n\nfunc main() {\n\twg := sync.WaitGroup{}\n\twg.Add(2)\n\tvar r1, r2 *taskMock\n\n\tgo func() {\n\t\tdefer wg.Done()\n\t\tr1 = servantgo.Run(\u0026taskMock{})\n\t}()\n\tgo func() {\n\t\tdefer wg.Done()\n\t\ttime.Sleep(time.Second * 2)\n\t\tr2 = servantgo.Run(\u0026taskMock{})\n\t}()\n\n\twg.Wait()\n\tfmt.Println(r1.result.String(), r2.result.String())\n}\n```\n\nIn this example we request two different instances of the same task to be run.\n\nThe task will take ~5 seconds to execute, and the second task will be sent for execution ~2 seconds after the first one.\n\nBoth tasks produce the same `Hash`, and therefore they are both considered identical by the library. As a result only the first one will execute, but its result will be returned to both.\n\nBecause of this the total execution time will be ~5 seconds.\n\n**NOTE:** The result returned to all _subscribed_ parties is the same one (same pointer).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktsivkov%2Fservantgo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fktsivkov%2Fservantgo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktsivkov%2Fservantgo/lists"}