{"id":15672344,"url":"https://github.com/posener/context","last_synced_at":"2025-10-08T11:18:45.696Z","repository":{"id":69603134,"uuid":"149877786","full_name":"posener/context","owner":"posener","description":"A proof of concept implementation of scoped context","archived":false,"fork":false,"pushed_at":"2019-04-13T16:57:37.000Z","size":20,"stargazers_count":16,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-06T21:09:06.614Z","etag":null,"topics":["context","go","golang","goroutine","proof-of-concept","scope"],"latest_commit_sha":null,"homepage":"https://posener.github.io/goroutine-scoped-context","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/posener.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2018-09-22T13:08:26.000Z","updated_at":"2021-08-23T11:43:14.000Z","dependencies_parsed_at":"2023-09-05T02:46:58.543Z","dependency_job_id":null,"html_url":"https://github.com/posener/context","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/posener/context","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posener%2Fcontext","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posener%2Fcontext/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posener%2Fcontext/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posener%2Fcontext/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/posener","download_url":"https://codeload.github.com/posener/context/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posener%2Fcontext/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278931706,"owners_count":26070801,"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-10-08T02:00:06.501Z","response_time":56,"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":["context","go","golang","goroutine","proof-of-concept","scope"],"created_at":"2024-10-03T15:24:28.300Z","updated_at":"2025-10-08T11:18:45.680Z","avatar_url":"https://github.com/posener.png","language":"Go","readme":"# context\n\nPackage context is a proof of concept implementation of **scoped context**,\nproposed in [this blog post](https://posener.github.io/goroutine-scoped-context).\n\nThis library should not be used for production code.\n\n#### Usage\n\nThe context package should be imported from `github.com/posener/context`.\n\n```diff\n import (\n-   \"context\"\n+   \"github.com/posener/context\"\n )\n```\n\nSince this implementation does not involve changes to the runtime,\nthe goroutine context must be initialized.\n\n```diff\n func main() {\n+\tcontext.Init()\n \t// Go code goes here.\n }\n```\n\nFunctions should not anymore receive the context in the first argument.\nThey should get it from the goroutine scope.\n\n```diff\n-func foo(ctx context.Context) {\n+func foo() {\n+\tctx := context.Get()\n \t// Use context.\n }\n```\n\nApplying context to a scope:\n\n```go\nunset := context.Set(ctx)\n// ctx is applied until unset is called, or a deeper `Set` call.\nunset()\n```\n\nOr:\n\n```go\ndefer context.Set(ctx)()\n// ctx is applied until the end of the function or a deeper `Set` call.\n```\n\nInvoking goroutines should be done with `context.Go` or `context.GoCtx`\n\nRunning a new goroutine with the current stored context:\n\n```diff\n-go foo()\n+context.Go(foo)\n```\n\nMore complected functions:\n\n```diff\n-go foo(1, \"hello\")\n+context.Go(func() { foo(1, \"hello\") })\n```\n\nRunning a goroutine with a new context:\n\n```go\n// `ctx` is the context that we want to have in the invoked goroutine\ncontext.GoCtx(ctx, foo)\n```\n\n`context.TODO` should not be used anymore:\n\n```diff\n-f(context.TODO())\n+f(context.Get())\n```\n\n## Sub Packages\n\n* [runtime](./runtime)\n\n\n---\n\nCreated by [goreadme](https://github.com/apps/goreadme)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposener%2Fcontext","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fposener%2Fcontext","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposener%2Fcontext/lists"}