{"id":22479641,"url":"https://github.com/nxdir-s/pipelines","last_synced_at":"2025-10-27T08:33:47.473Z","repository":{"id":252889562,"uuid":"841165618","full_name":"nxdir-s/pipelines","owner":"nxdir-s","description":"pipelines contains generic functions for concurrent processing","archived":false,"fork":false,"pushed_at":"2024-11-26T02:53:40.000Z","size":13,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-06T15:16:11.284Z","etag":null,"topics":["concurrency","go","golang","pipelines"],"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/nxdir-s.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}},"created_at":"2024-08-11T20:40:23.000Z","updated_at":"2024-11-26T02:53:39.000Z","dependencies_parsed_at":"2024-10-25T07:18:50.954Z","dependency_job_id":"6e44fda1-da98-467c-bc23-003b83adddbe","html_url":"https://github.com/nxdir-s/pipelines","commit_stats":null,"previous_names":["nxdir-s/pipelines"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nxdir-s%2Fpipelines","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nxdir-s%2Fpipelines/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nxdir-s%2Fpipelines/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nxdir-s%2Fpipelines/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nxdir-s","download_url":"https://codeload.github.com/nxdir-s/pipelines/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236721038,"owners_count":19194346,"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","go","golang","pipelines"],"created_at":"2024-12-06T15:16:15.476Z","updated_at":"2025-10-16T13:30:36.956Z","avatar_url":"https://github.com/nxdir-s.png","language":"Go","funding_links":[],"categories":["Data Structures and Algorithms","Data Integration Frameworks","数据结构与算法"],"sub_categories":["Pipes","管道"],"readme":"[![Go Reference](https://pkg.go.dev/badge/github.com/nxdir-s/pipelines.svg)](https://pkg.go.dev/github.com/nxdir-s/pipelines)\n[![Go Report Card](https://goreportcard.com/badge/github.com/nxdir-s/pipelines)](https://goreportcard.com/report/github.com/nxdir-s/pipelines)\n[![Go Coverage](https://github.com/nxdir-s/pipelines/wiki/coverage.svg)](https://raw.githack.com/wiki/nxdir-s/pipelines/coverage.html)\n\n# pipelines\n\nPipelines contains generic functions that help with concurrent processing\n\n## Usage\n\nA pipeline can be created from a slice or map\n\n```go\nstream := pipelines.StreamSlice(ctx, data)\n```\n\nOr from a generator function\n\n```go\nfunc GenerateData(ctx context.Context) int { return rand.Intn(10) }\n\nstream := pipelines.GenerateStream(ctx, GenerateData)\n```\n\n### FanOut\n\n`FanOut` can be used to process data concurrently. Useful for I/O bound processes, but it can be used in any situation where you have a slice or map of data and want to introduce concurrency\n\n```go\nconst MaxFan int = 3\n\nfanOutChannels := pipelines.FanOut(ctx, stream, ProcessFunc, MaxFan)\n```\n\n### FanIn\n\n`FanIn` can be used to merge data into one channel\n\n```go\nfanInData := pipelines.FanIn(ctx, fanOutChannels...)\n```\n\n## Example\n\n```go\npackage main\n\nimport (\n    \"context\"\n    \"fmt\"\n    \"math/rand\"\n    \"os\"\n    \"os/signal\"\n    \"strconv\"\n    \"time\"\n\n    \"github.com/nxdir-s/pipelines\"\n)\n\nconst (\n    MaxFan int = 3\n)\n\nfunc GenerateData(ctx context.Context) int {\n    return rand.Intn(5)\n}\n\nfunc Process(ctx context.Context, timeout int) string {\n    select {\n    case \u003c-ctx.Done():\n        return \"context cancelled\"\n    case \u003c-time.After(time.Second * time.Duration(timeout)):\n        return \"slept for \" + strconv.Itoa(timeout) + \" seconds!\"\n    }\n}\n\nfunc Read(ctx context.Context, messages \u003c-chan string) {\n    for msg := range messages {\n        select {\n        case \u003c-ctx.Done():\n            return\n        default:\n            fmt.Fprintf(os.Stdout, \"%s\\n\", msg)\n        }\n    }\n}\n\nfunc main() {\n    ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)\n    defer cancel()\n\n    stream := pipelines.GenerateStream(ctx, GenerateData)\n    fanOutChannels := pipelines.FanOut(ctx, stream, Process, MaxFan)\n    messages := pipelines.FanIn(ctx, fanOutChannels...)\n\n    go Read(ctx, messages)\n\n    select {\n    case \u003c-ctx.Done():\n        fmt.Fprint(os.Stdout, \"context canceled, exiting...\\n\")\n        os.Exit(0)\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnxdir-s%2Fpipelines","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnxdir-s%2Fpipelines","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnxdir-s%2Fpipelines/lists"}