{"id":30655109,"url":"https://github.com/daishe/go-future","last_synced_at":"2025-08-31T09:44:37.340Z","repository":{"id":310047706,"uuid":"1038509902","full_name":"daishe/go-future","owner":"daishe","description":"A tiny, dependency‑free implementation of futures that works nicely with Go’s concurrency primitives","archived":false,"fork":false,"pushed_at":"2025-08-15T10:43:39.000Z","size":56,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-08-15T12:25:28.210Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/daishe.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,"zenodo":null}},"created_at":"2025-08-15T10:34:28.000Z","updated_at":"2025-08-15T10:43:15.000Z","dependencies_parsed_at":"2025-08-15T12:25:52.528Z","dependency_job_id":"8d83b79f-07d6-4447-9dfa-944d98e10617","html_url":"https://github.com/daishe/go-future","commit_stats":null,"previous_names":["daishe/go-future"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/daishe/go-future","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daishe%2Fgo-future","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daishe%2Fgo-future/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daishe%2Fgo-future/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daishe%2Fgo-future/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daishe","download_url":"https://codeload.github.com/daishe/go-future/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daishe%2Fgo-future/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272965468,"owners_count":25023071,"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-08-31T02:00:09.071Z","response_time":79,"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":"2025-08-31T09:44:36.711Z","updated_at":"2025-08-31T09:44:37.297Z","avatar_url":"https://github.com/daishe.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Futures (for Golang)\n\nThe go-future module provides a tiny, dependency‑free implementation of futures (single‑value promises) that works nicely with Go’s existing concurrency primitives - if you only need to produce a single value once and let any number of goroutines read it later, future is a clear, safe abstraction.\n\nA Future[T] is a container that can be resolved exactly once and then read from any goroutine. They behave much like a channel with a capacity of 1: they hold a single value that can be produced once and consumed later (but any number of times, by any number of goroutines). They also provide a signaling mechanism (the Done channel) that is closed when the value becomes available, mirroring the way a buffered‑1 channel becomes readable once a send occurs.\n\nThe key distinction lies in broadcast capability - while a single‑value channel can be received by only one goroutine before it becomes empty again, a future stores the result and allows any number of receivers to obtain the same value after it is resolved, enabling the possibility to effectively broadcast a single result to many listeners. Additionally, futures never need to be closed, so users are freed from implementing any special channel‑closing logic when sharing a value across multiple goroutines.\n\n## Installing\n\nFirst, use go get to install the latest version of the library.\n\n```sh\ngo get -u github.com/daishe/go-future\n```\n\nNext, include go-future in your application:\n\n```go\nimport \"github.com/daishe/go-future\"\n```\n\n## Quick start\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"sync\"\n\t\"time\"\n\n\t\"github.com/daishe/go-future\"\n)\n\nfunc asyncOperation() *future.Future[int] {\n\tf := \u0026future.Future[int]{}\n\tgo func() {\n\t\ttime.Sleep(500 * time.Millisecond) // simulate work\n\t\tf.Resolve(42)\n\t}()\n\treturn f\n}\n\nfunc main() {\n\tf := asyncOperation()\n\twg := \u0026sync.WaitGroup{}\n\n\t// (1) Client that block until the value is ready\n\twg.Add(1)\n\tgo func() {\n\t\tdefer wg.Done()\n\t\tfmt.Println(\"Result:\", f.Get())\n\t}()\n\n\t// (2) Client that react to completion via Done()\n\twg.Add(1)\n\tgo func() {\n\t\tdefer wg.Done()\n\t\tselect {\n\t\tcase \u003c-f.Done():\n\t\t\tfmt.Println(\"Future resolved to\", f.Get())\n\t\t}\n\t}()\n\n\t// (3) Client that uses cancelable waiting with a context\n\twg.Add(1)\n\tgo func() {\n\t\tdefer wg.Done()\n\t\tctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond)\n\t\tdefer cancel()\n\t\tif future.Await(ctx, f.Done()) {\n\t\t\tfmt.Println(\"Got result before timeout:\", f.Get())\n\t\t} else {\n\t\t\tfmt.Println(\"Timed out!\")\n\t\t}\n\t}()\n\n\twg.Wait()\n}\n```\n\nPossible output:\n\n```out\nTimed out!\nResult: 42\nFuture resolved to 42\n```\n\nSee `examples` directory for more usage examples.\n\n## License\n\nThe project is released under the **Apache License, Version 2.0**. See the full LICENSE file for the complete terms and conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaishe%2Fgo-future","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaishe%2Fgo-future","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaishe%2Fgo-future/lists"}