{"id":13413050,"url":"https://github.com/workanator/go-floc","last_synced_at":"2026-02-03T14:36:45.669Z","repository":{"id":41812498,"uuid":"96083021","full_name":"workanator/go-floc","owner":"workanator","description":"Floc: Orchestrate goroutines with ease.","archived":false,"fork":false,"pushed_at":"2021-08-10T10:33:23.000Z","size":263,"stargazers_count":268,"open_issues_count":1,"forks_count":17,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-08-13T17:43:51.527Z","etag":null,"topics":["go","golang-library","goroutine-order","goroutine-safe","goroutines","parallel-programming"],"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/workanator.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-03T07:34:06.000Z","updated_at":"2025-02-28T03:02:18.000Z","dependencies_parsed_at":"2022-09-11T10:40:17.383Z","dependency_job_id":null,"html_url":"https://github.com/workanator/go-floc","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/workanator/go-floc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workanator%2Fgo-floc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workanator%2Fgo-floc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workanator%2Fgo-floc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workanator%2Fgo-floc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/workanator","download_url":"https://codeload.github.com/workanator/go-floc/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workanator%2Fgo-floc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29047566,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-03T10:09:22.136Z","status":"ssl_error","status_checked_at":"2026-02-03T10:09:16.814Z","response_time":96,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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-library","goroutine-order","goroutine-safe","goroutines","parallel-programming"],"created_at":"2024-07-30T20:01:32.834Z","updated_at":"2026-02-03T14:36:45.645Z","avatar_url":"https://github.com/workanator.png","language":"Go","funding_links":[],"categories":["Goroutines","Goroutines `goroutines的管理和使用`","\u003cspan id=\"协程-Coroutines\"\u003e协程 Coroutines\u003c/span\u003e","Relational Databases"],"sub_categories":["Search and Analytic Databases","检索及分析资料库","Advanced Console UIs","SQL 查询语句构建库","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e"],"readme":"![Gopher Floc Control](https://github.com/workanator/repo-faces/blob/main/go-floc/main.png)\n\n# go-floc\nFloc: Orchestrate goroutines with ease.\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/workanator/go-floc.svg)](https://pkg.go.dev/github.com/workanator/go-floc)\n[![Build Status](https://travis-ci.org/workanator/go-floc.svg?branch=main)](https://travis-ci.org/workanator/go-floc)\n[![Coverage Status](https://coveralls.io/repos/github/workanator/go-floc/badge.svg?branch=main)](https://coveralls.io/github/workanator/go-floc?branch=main)\n[![Go Report Card](https://goreportcard.com/badge/github.com/workanator/go-floc)](https://goreportcard.com/report/github.com/workanator/go-floc)\n[![Join the chat at https://gitter.im/go-floc/Lobby](https://badges.gitter.im/go-floc/Lobby.svg)](https://gitter.im/go-floc/Lobby?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n[![License](https://img.shields.io/dub/l/vibe-d.svg)](https://github.com/workanator/go-floc/blob/main/LICENSE)\n\nThe goal of the project is to make the process of running goroutines in parallel\nand synchronizing them easy.\n\n## Announcements\n\n`v3` released! The new version keeps the same design as `v2` but it distributed now as a Go module and therefore\nit has breaking changes.\n\n## Migration from v2 to v3\n\n1. Install the package with `go get github.com/workanator/go-floc/v3`\n2. Replace all old paths `gopkg.in/workanator/go-floc` to `github.com/workanator/go-floc/v3`\n3. All types from `errors` sub-package moved to the base package `go-floc`. So please, remove all imports of\n   `\"gopkg.in/workanator/go-floc/errors\"` if any and fix type names, e.g. `errors.ErrTimeout` -\u003e `floc.ErrTimeout`\n\n## Installation and requirements\n\nThe package requires Go v1.12 or later.\n\nTo install the package use `go get github.com/workanator/go-floc/v3`\n\n## Documentation and examples\n\nPlease refer [Godoc reference](https://pkg.go.dev/github.com/workanator/go-floc)\nof the package for more details.\n\nSome examples are available at the Godoc reference. Additional examples can\nbe found in [go-floc-showcase](https://github.com/workanator/go-floc-showcase?branch=v3).\n\n## Features\n\n- Easy to use functional interface.\n- Simple parallelism and synchronization of jobs.\n- As little overhead as possible, in comparison to direct use of goroutines\nand sync primitives.\n- Provide better control over execution with one entry point and one exit\npoint.\n\n## Introduction\n\nFloc introduces some terms which are widely used through the package.\n\n### Flow\n\nFlow is the overall process which can be controlled through `floc.Flow`. Flow\ncan be canceled or completed with any arbitrary data at any point of execution.\nFlow has only one enter point and only one exit point.\n\n```go\n// Design the job\nflow := run.Sequence(do, something, here, ...)\n\n// The enter point: Run the job\nresult, data, err := floc.Run(flow)\n\n// The exit point: Check the result of the job.\nif err != nil {\n\t// Handle the error\n} else if result.IsCompleted() {\n\t// Handle the success\n} else {\n\t// Handle other cases\n}\n```\n\n### Job\n\nJob in Floc is a smallest piece of flow. The prototype of job function is\n`floc.Job`. Each job can read/write data with `floc.Context` and control\nthe flow with `floc.Control`.\n\n`Cancel()`, `Complete()`, `Fail()` methods of `floc.Flow` has permanent effect.\nOnce finished flow cannot be canceled or completed anymore. Calling `Fail` and\nreturning error from job is almost equal.\n\n```go\nfunc ValidateContentLength(ctx floc.Context, ctrl floc.Control) error {\n  request := ctx.Value(\"request\").(http.Request)\n\n  // Cancel the flow with error if request body size is too big\n  if request.ContentLength \u003e MaxContentLength {\n    return errors.New(\"content is too big\")\n  }\n  \n  return nil\n}\n```\n\n## Example\n\nLets have some fun and write a simple example which calculates some statistics\non text given.\n\n```go\nconst Text = `Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed\n  do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim\n  veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo\n  consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum\n  dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident,\n  sunt in culpa qui officia deserunt mollit anim id est laborum.`\n\ntype myKey int\nconst keyStatistics myKey = 1\n\nvar sanitizeWordRe = regexp.MustCompile(`\\W`)\n\ntype Statistics struct {\n  Words      []string\n  Characters int\n  Occurrence map[string]int\n}\n\n// Split to words and sanitize them\nSplitToWords := func(ctx floc.Context, ctrl floc.Control) error {\n  statistics := ctx.Value(keyStatistics).(*Statistics)\n\n  statistics.Words = strings.Split(Text, \" \")\n  for i, word := range statistics.Words {\n    statistics.Words[i] = sanitizeWordRe.ReplaceAllString(word, \"\")\n  }\n  \n  return nil\n}\n\n// Count and sum the number of characters in the each word\nCountCharacters := func(ctx floc.Context, ctrl floc.Control) error {\n  statistics := ctx.Value(keyStatistics).(*Statistics)\n\n  for _, word := range statistics.Words {\n    statistics.Characters += len(word)\n  }\n  \n  return nil\n}\n\n// Count the number of unique words\nCountUniqueWords := func(ctx floc.Context, ctrl floc.Control) error {\n  statistics := ctx.Value(keyStatistics).(*Statistics)\n\n  statistics.Occurrence = make(map[string]int)\n  for _, word := range statistics.Words {\n    statistics.Occurrence[word] = statistics.Occurrence[word] + 1\n  }\n  \n  return nil\n}\n\n// Print result\nPrintResult := func(ctx floc.Context, ctrl floc.Control) error {\n  statistics := ctx.Value(keyStatistics).(*Statistics)\n\n  fmt.Printf(\"Words Total       : %d\\n\", len(statistics.Words))\n  fmt.Printf(\"Unique Word Count : %d\\n\", len(statistics.Occurrence))\n  fmt.Printf(\"Character Count   : %d\\n\", statistics.Characters)\n  \n  return nil\n}\n\n// Design the flow and run it\nflow := run.Sequence(\n  SplitToWords,\n  run.Parallel(\n    CountCharacters,\n    CountUniqueWords,\n  ),\n  PrintResult,\n)\n\nctx := floc.NewContext()\nctx.AddValue(keyStatistics, new(Statistics))\n\nctrl := floc.NewControl(ctx)\n\n_, _, err := floc.RunWith(ctx, ctrl, flow)\nif err != nil {\n\tpanic(err)\n}\n\n// Output:\n// Words Total       : 64\n// Unique Word Count : 60\n// Character Count   : 370\n```\n\n## Contributing\n\nPlease found information about contributing in\n[CONTRIBUTING.md](CONTRIBUTING.md)\nand the list of braves who spent their priceless time and effort to make the project better in\n[CONTRIBUTORS.md](CONTRIBUTORS.md).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworkanator%2Fgo-floc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fworkanator%2Fgo-floc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworkanator%2Fgo-floc/lists"}