{"id":20566228,"url":"https://github.com/telkomdev/gaw","last_synced_at":"2025-10-16T09:48:39.697Z","repository":{"id":38345159,"uuid":"505289443","full_name":"telkomdev/gaw","owner":"telkomdev","description":"Small library to mimic Node's Async Await with Golang","archived":false,"fork":false,"pushed_at":"2022-06-24T03:07:05.000Z","size":18,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-06T08:57:43.656Z","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/telkomdev.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-06-20T04:05:27.000Z","updated_at":"2022-06-23T07:49:23.000Z","dependencies_parsed_at":"2022-08-28T12:01:12.209Z","dependency_job_id":null,"html_url":"https://github.com/telkomdev/gaw","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/telkomdev/gaw","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/telkomdev%2Fgaw","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/telkomdev%2Fgaw/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/telkomdev%2Fgaw/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/telkomdev%2Fgaw/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/telkomdev","download_url":"https://codeload.github.com/telkomdev/gaw/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/telkomdev%2Fgaw/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274049454,"owners_count":25213637,"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","status":"online","status_checked_at":"2025-09-07T02:00:09.463Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":"2024-11-16T04:40:40.525Z","updated_at":"2025-10-16T09:48:34.649Z","avatar_url":"https://github.com/telkomdev.png","language":"Go","readme":"## Gaw (Go Async Await)\n\nSmall library to mimic `Node's Async Await` with `Golang`\n\n[![gaw CI](https://github.com/telkomdev/gaw/actions/workflows/ci.yml/badge.svg)](https://github.com/telkomdev/gaw/actions/workflows/ci.yml)\n[![Go Reference](https://pkg.go.dev/badge/github.com/telkomdev/gaw.svg)](https://pkg.go.dev/github.com/telkomdev/gaw)\n\n#\n\n\n### Requirements\n- Go 1.18+ (because `gaw` uses generic features)\n\n### Install\n\n```shell\n$ go get github.com/telkomdev/gaw\n```\n\n### Basic Usage\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"github.com/telkomdev/gaw\"\n\t\"time\"\n)\n\ntype Event struct {\n\tID   string\n\tName string\n}\n\nfunc (e *Event) String() string {\n\treturn fmt.Sprintf(\"event id: %s\\nevent name: %s\\n\", e.ID, e.Name)\n}\n\nfunc main() {\n\tasync := gaw.Async[*Event](context.Background(), func() (*Event, error) {\n\t\t// simulate heavy work that takes 3 seconds to finish\n\t\ttime.Sleep(time.Second * 3)\n\n\t\treturn \u0026Event{ID: \"111\", Name: \"Order Request\"}, nil\n\t})\n\n\t// do other work while waiting async to finish\n\tfmt.Println(\"do other work\")\n\n\t// call Await\n\tasync.Await()\n\n\tfmt.Println(\"work done\")\n\n\t// check if its error\n\tif async.IsErr() {\n\t\tfmt.Printf(\"async error: %v\\n\", async.Err())\n\t} else {\n        // no error\n        // get the value\n\t\tfmt.Println(async.Get())\n\t}\n}\n\n```\n\n### AsyncAll\n\nCall multiple function in `async` mode, and get the multiple results\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"net\"\n\t\"net/http\"\n\t\"time\"\n\n\t\"github.com/telkomdev/gaw\"\n)\n\nfunc httpGet(url string) (*http.Response, error) {\n\ttransport := \u0026http.Transport{\n\t\tDial: (\u0026net.Dialer{\n\t\t\tTimeout: 5 * time.Second,\n\t\t}).Dial,\n\t\tTLSHandshakeTimeout: 5 * time.Second,\n\t\tIdleConnTimeout:     10 * time.Second,\n\t}\n\n\thttpClient := \u0026http.Client{\n\t\t//Timeout:   time.Second * 10,\n\t\tTransport: transport,\n\t}\n\treq, err := http.NewRequest(\"GET\", url, nil)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tresponse, err := httpClient.Do(req)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn response, nil\n}\n\nfunc main() {\n\turl := \"https://www.w3schools.com/js/default.asp\"\n\n\tf1 := func() (*http.Response, error) {\n\t\tresp, err := httpGet(url)\n\n\t\treturn resp, err\n\t}\n\n\tf2 := func() (*http.Response, error) {\n\t\tresp, err := httpGet(url)\n\n\t\treturn resp, err\n\t}\n\n\tf3 := func() (*http.Response, error) {\n\t\tresp, err := httpGet(url)\n\n\t\treturn resp, err\n\t}\n\n\tasyncAll := gaw.AsyncAll[*http.Response](ctx, f1, f2, f3)\n\n\t// do other work while waiting async to finish\n\tfmt.Println(\"do other work\")\n\n\t// call Await\n\tasyncAll.Await()\n\n\tfmt.Println(\"work done\")\n\n\tfor _, resp := range asyncAll.Get() {\n\n\t\tfmt.Println(resp)\n\t\tfmt.Println(\"----\")\n\t}\n}\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftelkomdev%2Fgaw","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftelkomdev%2Fgaw","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftelkomdev%2Fgaw/lists"}