{"id":41145774,"url":"https://github.com/func25/gowait","last_synced_at":"2026-01-22T18:55:45.321Z","repository":{"id":57694756,"uuid":"487660773","full_name":"func25/gowait","owner":"func25","description":null,"archived":false,"fork":false,"pushed_at":"2022-05-11T23:46:09.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-06-20T11:02:58.309Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/func25.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}},"created_at":"2022-05-01T22:59:33.000Z","updated_at":"2024-04-27T13:22:51.000Z","dependencies_parsed_at":"2022-09-14T22:21:11.152Z","dependency_job_id":null,"html_url":"https://github.com/func25/gowait","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/func25/gowait","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/func25%2Fgowait","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/func25%2Fgowait/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/func25%2Fgowait/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/func25%2Fgowait/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/func25","download_url":"https://codeload.github.com/func25/gowait/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/func25%2Fgowait/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28668643,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-22T17:07:18.858Z","status":"ssl_error","status_checked_at":"2026-01-22T17:05:02.040Z","response_time":144,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":"2026-01-22T18:55:44.840Z","updated_at":"2026-01-22T18:55:45.314Z","avatar_url":"https://github.com/func25.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gowait\r\n\r\nInstead of cronjob, you can schedule a job run at a specific time, run after X duration, panic retry,... \r\n\r\n* [Installation](#installation)\r\n* [Samples](#samples)\r\n  * [Schedule a job](#schedule-a-job)\r\n  * [Schedule a REPEAT job](#schedule-a-repeat-job)\r\n  * [Options](#options-panic-custom-duration)\r\n* [Status](#status-pre-release)\r\n\r\n## Installation\r\n\r\n`go get github.com/func25/gowait`\r\n\r\n## Samples\r\n\r\n### Schedule a job\r\n\r\nSchedule a job run in 3 seconds later:\r\n\r\n```go\r\nvar start int64\r\n\r\nfunc main() {\r\n\tstart = time.Now().Unix()\r\n\tgowait.DurationJob(time.Second*3, showTime)\r\n\r\n\ttime.Sleep(time.Second * 4)\r\n}\r\n\r\nfunc showTime() {\r\n\tfmt.Println(\"show time:\", time.Now().Unix() - start)\r\n}\r\n\r\n```\r\n\r\nThe result of course will be:\r\n```\r\nshow time: 3\r\n```\r\n\r\n### Schedule a REPEAT job\r\n\r\nSchedule a job run in 3 seconds later and also run EVERY 3 seconds, if you want to stop, just return nil in the job\r\n```go\r\nvar start int64\r\n\r\nfunc main() {\r\n\tstart = time.Now().Unix()\r\n\tgowait.DurationJobLoop(showTimeLoop, time.Second*3)\r\n\r\n\ttime.Sleep(time.Second * 10)\r\n}\r\n\r\nfunc showTimeLoop() *time.Duration {\r\n\tfmt.Println(\"show time:\", time.Now().Unix()-start)\r\n\tnext := time.Second * 3\r\n\treturn \u0026next\r\n}\r\n```\r\n\r\n```go\r\nshow time: 3\r\nshow time: 6\r\nshow time: 9\r\n```\r\n\r\n### Options: panic, custom duration,...\r\nTo use our option, you should create an \"option generator\", in the below example, the job will run at 1 second later\r\n- **ZeroDuration**: if the job return \u003c= 0 duration time, then we apply 1 second to the duration (avoid spamming).\r\n- **MinDuration**: this will be more prioritized than zeroDuration.\r\n- **PanicRetry**: retry the job if any panic occurs and what time is it run next time.\r\n\r\n```go\r\nvar startTime int64\r\nfunc main() {\r\n\tstartTime = time.Now().Unix()\r\n\t\r\n\tg := gowait.RepeatOptGen{} \"option generator\"\r\n\tgowait.ScheduleJobLoop(loopTime, time.Now().Add(time.Second),\r\n\t\tg.ZeroDuration(time.Second), // zeroDuration will be 2s (minDuration have higher priority)\r\n\t\tg.MinDuration(2*time.Second),\r\n\t\tg.PanicRetry(true, 3*time.Second),\r\n\t)\r\n\t\r\n\ttime.Sleep(time.Hour)\r\n}\r\n\r\nfunc loopTime() *time.Time {\r\n\tdis := time.Now().Unix() - startTime\r\n\tfmt.Println(\"show time:\", dis)\r\n\tx := time.Now().Add(time.Second * 1) // run next 1 second\r\n\r\n\tif dis == 5 {\r\n\t\tfmt.Println(\"zeroDuration\")\r\n\t\tx = time.Now() // test zeroDuration + minDuration\r\n\t}\r\n\r\n\tif dis \u003e 10 { // test panic\r\n\t\tfmt.Println(\"panic\")\r\n\t\tpanic(\"dis \u003e 10\")\r\n\t}\r\n\r\n\treturn \u0026x\r\n}\r\n```\r\n\r\n```go\r\nshow time: 1\r\nshow time: 3\r\nshow time: 5\r\nzeroDuration\r\nshow time: 7\r\nshow time: 9\r\nshow time: 11\r\npanic\r\nshow time: 14\r\npanic\r\nshow time: 17\r\npanic\r\nshow time: 20\r\npanic\r\n```\r\n\r\n## Status: pre-release\r\nThis lib is under developing, please notice when using it\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffunc25%2Fgowait","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffunc25%2Fgowait","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffunc25%2Fgowait/lists"}