{"id":13692472,"url":"https://github.com/modern-go/concurrent","last_synced_at":"2025-05-02T19:32:08.120Z","repository":{"id":41312243,"uuid":"123229061","full_name":"modern-go/concurrent","owner":"modern-go","description":"concurrency utilities","archived":false,"fork":false,"pushed_at":"2019-08-09T12:06:02.000Z","size":24,"stargazers_count":295,"open_issues_count":7,"forks_count":25,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-25T00:04:17.017Z","etag":null,"topics":["concurrency","concurrent","go","golang"],"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/modern-go.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":"2018-02-28T04:28:22.000Z","updated_at":"2025-04-23T12:43:22.000Z","dependencies_parsed_at":"2022-08-10T01:54:04.316Z","dependency_job_id":null,"html_url":"https://github.com/modern-go/concurrent","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modern-go%2Fconcurrent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modern-go%2Fconcurrent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modern-go%2Fconcurrent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modern-go%2Fconcurrent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/modern-go","download_url":"https://codeload.github.com/modern-go/concurrent/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252095355,"owners_count":21693903,"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","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":["concurrency","concurrent","go","golang"],"created_at":"2024-08-02T17:00:58.363Z","updated_at":"2025-05-02T19:32:07.887Z","avatar_url":"https://github.com/modern-go.png","language":"Go","readme":"# concurrent\n\n[![Sourcegraph](https://sourcegraph.com/github.com/modern-go/concurrent/-/badge.svg)](https://sourcegraph.com/github.com/modern-go/concurrent?badge)\n[![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](http://godoc.org/github.com/modern-go/concurrent)\n[![Build Status](https://travis-ci.org/modern-go/concurrent.svg?branch=master)](https://travis-ci.org/modern-go/concurrent)\n[![codecov](https://codecov.io/gh/modern-go/concurrent/branch/master/graph/badge.svg)](https://codecov.io/gh/modern-go/concurrent)\n[![rcard](https://goreportcard.com/badge/github.com/modern-go/concurrent)](https://goreportcard.com/report/github.com/modern-go/concurrent)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://raw.githubusercontent.com/modern-go/concurrent/master/LICENSE)\n\n* concurrent.Map: backport sync.Map for go below 1.9\n* concurrent.Executor: goroutine with explicit ownership and cancellable\n\n# concurrent.Map\n\nbecause sync.Map is only available in go 1.9, we can use concurrent.Map to make code portable\n\n```go\nm := concurrent.NewMap()\nm.Store(\"hello\", \"world\")\nelem, found := m.Load(\"hello\")\n// elem will be \"world\"\n// found will be true\n```\n\n# concurrent.Executor\n\n```go\nexecutor := concurrent.NewUnboundedExecutor()\nexecutor.Go(func(ctx context.Context) {\n    everyMillisecond := time.NewTicker(time.Millisecond)\n    for {\n        select {\n        case \u003c-ctx.Done():\n            fmt.Println(\"goroutine exited\")\n            return\n        case \u003c-everyMillisecond.C:\n            // do something\n        }\n    }\n})\ntime.Sleep(time.Second)\nexecutor.StopAndWaitForever()\nfmt.Println(\"executor stopped\")\n```\n\nattach goroutine to executor instance, so that we can\n\n* cancel it by stop the executor with Stop/StopAndWait/StopAndWaitForever\n* handle panic by callback: the default behavior will no longer crash your application","funding_links":[],"categories":["开源类库","Open source library","Go"],"sub_categories":["并发","Concurrency"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmodern-go%2Fconcurrent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmodern-go%2Fconcurrent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmodern-go%2Fconcurrent/lists"}