{"id":20512615,"url":"https://github.com/felix-kaestner/promise","last_synced_at":"2026-06-10T07:31:17.744Z","repository":{"id":57660203,"uuid":"474996235","full_name":"felix-kaestner/promise","owner":"felix-kaestner","description":"Go Promise Implementation with support for Generics (requires Go v1.18+)","archived":false,"fork":false,"pushed_at":"2024-06-10T01:12:46.000Z","size":44,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-05T22:47:38.189Z","etag":null,"topics":["go","golang","goroutine","promise"],"latest_commit_sha":null,"homepage":"","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/felix-kaestner.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"felix-kaestner"}},"created_at":"2022-03-28T12:40:04.000Z","updated_at":"2022-03-28T17:14:29.000Z","dependencies_parsed_at":"2024-11-18T07:47:16.220Z","dependency_job_id":null,"html_url":"https://github.com/felix-kaestner/promise","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":"felix-kaestner/go-library-template","purl":"pkg:github/felix-kaestner/promise","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felix-kaestner%2Fpromise","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felix-kaestner%2Fpromise/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felix-kaestner%2Fpromise/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felix-kaestner%2Fpromise/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/felix-kaestner","download_url":"https://codeload.github.com/felix-kaestner/promise/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felix-kaestner%2Fpromise/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34142637,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-10T02:00:07.152Z","response_time":89,"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":["go","golang","goroutine","promise"],"created_at":"2024-11-15T20:42:09.422Z","updated_at":"2026-06-10T07:31:17.726Z","avatar_url":"https://github.com/felix-kaestner.png","language":"Go","funding_links":["https://github.com/sponsors/felix-kaestner"],"categories":[],"sub_categories":[],"readme":"# Promise\n\n\u003cp align=\"center\"\u003e\n    \u003cspan\u003eGo Promise Implementation with support for Generics (requires Go v1.18+).\u003c/span\u003e\n    \u003cbr\u003e\n    \u003cspan\u003eRun async operations lazily in a separate goroutine on the fly.\u003c/span\u003e\n    \u003cbr\u003e\u003cbr\u003e\n    \u003ca href=\"https://github.com/felix-kaestner/promise/issues\"\u003e\n        \u003cimg alt=\"Issues\" src=\"https://img.shields.io/github/issues/felix-kaestner/promise?color=29b6f6\u0026style=flat-square\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/felix-kaestner/promise/stargazers\"\u003e\n        \u003cimg alt=\"Stars\" src=\"https://img.shields.io/github/stars/felix-kaestner/promise?color=29b6f6\u0026style=flat-square\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/felix-kaestner/promise/blob/main/LICENSE\"\u003e\n        \u003cimg alt=\"License\" src=\"https://img.shields.io/github/license/felix-kaestner/promise?color=29b6f6\u0026style=flat-square\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://pkg.go.dev/github.com/felix-kaestner/promise\"\u003e\n        \u003cimg alt=\"Stars\" src=\"https://img.shields.io/badge/go-documentation-blue?color=29b6f6\u0026style=flat-square\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://goreportcard.com/report/github.com/felix-kaestner/promise\"\u003e\n        \u003cimg alt=\"Issues\" src=\"https://goreportcard.com/badge/github.com/felix-kaestner/promise?style=flat-square\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://codecov.io/gh/felix-kaestner/promise\"\u003e\n        \u003cimg src=\"https://img.shields.io/codecov/c/github/felix-kaestner/promise?style=flat-square\u0026token=fkA8YwGXkk\"/\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://twitter.com/kaestner_felix\"\u003e\n        \u003cimg alt=\"Twitter\" src=\"https://img.shields.io/badge/twitter-@kaestner_felix-29b6f6?style=flat-square\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n## Features\n\n* Easy interface for composing async operations\n* Executes a function in a separate goroutine\n* Error Handling using functions (also executed in a separate goroutine)\n* Support for Generics (requires Go v1.18+)\n* Promises are resolved **lazily**, upon a first call to `Await`, `AwaitOr`, `Then`, `OnSuccess` or `onFailure`\n* Support for `promise.All` and `promise.Race` (equivalent to the JavaScript [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) object) \n\n## Quickstart\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\"net/http\"\n\n\t\"github.com/felix-kaestner/promise\"\n)\n\nfunc main() {\n    // Create a new promise.\n    // In this example the http request is executed in a separate goroutine\n    p := promise.New(func() (*http.Response, error) {\n        return http.Get(\"https://jsonplaceholder.typicode.com/posts/1\")\n    })\n    \n    // Handle successful and failed operations in a separate goroutine\n    p.Then(func(res *http.Response) {\n        log.Printf(\"Status: %s\", res.Status)\n    }, func(err error) {\n        log.Fatalln(err)\n    })\n\n    // Handle only successful operations in a separate goroutine\n    p.onSuccess(func(res *http.Response) {\n        log.Printf(\"Status: %s\", res.Status)\n    })\n\n    // Handle only failed operations in a separate goroutine\n    p.onFailure(func(err error) {\n        log.Fatalln(err)\n    })\n\n    // Await the promise.\n    // This blocks execution until the promise is resolved.\n    res, err := p.Await()\n    \n    // Provide a default value (calls Await() internally).\n    res = p.AwaitOr(nil)\n\n    // Use channels to select the awaited promise \n    select {\n    case \u003c-p.Done():\n        res, err = p.Await() // returns immediately since the promise is already resolved\n    case \u003c-time.After(5000 * time.Millisecond):\n        fmt.Println(\"Timeout\")\n    }\n\n    // Take multiple promises and wait for all of them to be finished\n    p1 := promise.New(func() (*http.Response, error) {\n        return http.Get(\"https://jsonplaceholder.typicode.com/posts/1\")\n    })\n    p2 := promise.New(func() (*http.Response, error) {\n        return http.Get(\"https://jsonplaceholder.typicode.com/posts/2\")\n    })\n    res, err := promise.All(p1, p2).Await()\n\n    // Take multiple promises and wait until the first of them to is finished\n    p1 := promise.New(func() (*http.Response, error) {\n        return http.Get(\"https://jsonplaceholder.typicode.com/posts/3\")\n    })\n    p2 := promise.New(func() (*http.Response, error) {\n        return http.Get(\"https://jsonplaceholder.typicode.com/posts/4\")\n    })\n    res, err := promise.Race(p1, p2).Await()\n\n}\n```\n\n##  Installation\n\nInstall with the `go get` command:\n\n```\n$ go get -u github.com/felix-kaestner/promise\n```\n\n## Contribute\n\nAll contributions in any form are welcome! 🙌🏻  \nJust use the [Issue](.github/ISSUE_TEMPLATE) and [Pull Request](.github/PULL_REQUEST_TEMPLATE) templates and I'll be happy to review your suggestions. 👍\n\n---\n\nReleased under the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffelix-kaestner%2Fpromise","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffelix-kaestner%2Fpromise","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffelix-kaestner%2Fpromise/lists"}