{"id":19816108,"url":"https://github.com/nofeaturesonlybugs/routines","last_synced_at":"2026-06-10T12:31:36.647Z","repository":{"id":57551859,"uuid":"292409198","full_name":"nofeaturesonlybugs/routines","owner":"nofeaturesonlybugs","description":"golang go routine management.","archived":false,"fork":false,"pushed_at":"2022-06-12T18:15:01.000Z","size":14,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-28T19:39:30.801Z","etag":null,"topics":["concurrency","concurrent-programming","context","go","golang","goroutine","goroutines","multiprocessing","multithreading","waitgroup"],"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/nofeaturesonlybugs.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.txt","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":"2020-09-02T22:36:06.000Z","updated_at":"2022-06-12T18:14:56.000Z","dependencies_parsed_at":"2022-09-26T18:41:38.691Z","dependency_job_id":null,"html_url":"https://github.com/nofeaturesonlybugs/routines","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/nofeaturesonlybugs/routines","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nofeaturesonlybugs%2Froutines","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nofeaturesonlybugs%2Froutines/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nofeaturesonlybugs%2Froutines/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nofeaturesonlybugs%2Froutines/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nofeaturesonlybugs","download_url":"https://codeload.github.com/nofeaturesonlybugs/routines/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nofeaturesonlybugs%2Froutines/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34153482,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-10T02:00:07.152Z","response_time":89,"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":["concurrency","concurrent-programming","context","go","golang","goroutine","goroutines","multiprocessing","multithreading","waitgroup"],"created_at":"2024-11-12T10:08:24.387Z","updated_at":"2026-06-10T12:31:36.623Z","avatar_url":"https://github.com/nofeaturesonlybugs.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Go Reference](https://pkg.go.dev/badge/github.com/nofeaturesonlybugs/routines.svg)](https://pkg.go.dev/github.com/nofeaturesonlybugs/routines)\n[![Go Report Card](https://goreportcard.com/badge/github.com/nofeaturesonlybugs/routines)](https://goreportcard.com/report/github.com/nofeaturesonlybugs/routines)\n[![Build Status](https://app.travis-ci.com/nofeaturesonlybugs/routines.svg?branch=master)](https://app.travis-ci.com/nofeaturesonlybugs/routines)\n[![codecov](https://codecov.io/gh/nofeaturesonlybugs/routines/branch/master/graph/badge.svg)](https://codecov.io/gh/nofeaturesonlybugs/routines)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n# Routines\n\nGolang package for enhanced goroutine synchronization and well defined idiomatic Golang services.\n\n# Dependencies\n\n-   github.com/nofeaturesonlybugs/errors\n\n# Write Idiomatic Client Code\n\n`bus` and `listen` are considered mock packages for this example.\n\n```go\nfunc fatal(e err) {\n    if e != nil {\n        fmt.Println(\"Error\", e)\n        os.Exit(255)\n    }\n}\n\nfunc main() {\n    // Top-level Routines object.\n    rtns := routines.NewRoutines()\n    // WaitGroup-like behavior providing clean shutdown.\n    defer rtns.Wait()\n\n    bus := bus.NewBus()\n    err := bus.Start(rtns)\n    fatal(err)\n    defer bus.Stop()\n\n    listener, err := listen.New(\"localhost:8080\")\n    fatal(err)\n    err = listener.Start(rtns)\n    fatal(err)\n    defer listener.Stop()\n\n    // Program stalls waiting on sigc or other shutdown signal...\n}\n```\n\nThe preceding example demonstrates the following well-defined behaviors:\n\n-   Calls to Start() block until the service is fully started, preventing race conditions\n    -   Returns an error if the service can not start\n-   Calls to Stop() block until the service is fully stopped, preventing race conditions\n\n# Write Lean Services\n\nThe `Service` interface provides the well-defined behavior of `Start` and `Stop` without polluting your service implementation.\n\n```go\ntype MyService struct {\n    Routines.Service\n}\n\nfunc NewMyService() *MyService {\n    rv := \u0026MyService{}\n    rv.Service = routines.NewService(rv.start)\n    return rv\n}\n\nfunc (me *MyService) start(rtns routines.Routines) error {\n    listener, err := net.Listen(\"localhost:8080\")\n    if err != nil {\n        return err\n    }\n    closed := make(chan struct{}, 1)\n\n    // Create a lambda function that handls the connection; we'll pass the\n    // returned function to rtns.Go() to ensure all handlers are finished\n    // when the service stops.\n    handler := func(c net.Conn) func() {\n        return func() {\n            io.Copy(c, c)\n            c.Close()\n        }\n    }\n    // Continuous loop that accepts and handles connections.\n    accept := func() {\n        for {\n            if conn, err := listener.Accept(); err != nil {\n                select {\n                    case \u003c-closed:\n                        goto done\n                    default:\n                        // Handle error\n                }\n            } else {\n                rtns.Go(handler(conn))\n            }\n        }\n        done:\n    }\n    // When rtns.Done() signals we close the listener; this ends the accept\n    // function.\n    cleanup := func() {\n        \u003c- rtns.Done()\n        close(closed)\n        listener.Close()\n    }\n    rtns.Go(cleanup)\n    rtns.Go(accept)\n    return nil\n}\n```\n\nThe preceding example is not concerned with the concurrency primitives required to implement correct `Start` and `Stop` behavior; it is only concerned with correctly implementing the service behavior.\n\nAll goroutines created by the service are invoked with `rtns.Go()`. This ensures clean shutdown when the client calls `Stop()` as `Stop()` will not return until all such goroutines have completed.\n\nAlso notice that the `struct` itself is not storing any variables or resources created as part of starting the service. Such resources are instantiated in the call to `start()` and then remembered by the goroutines of the service. When the service is stopped all of these goroutines will end; the handles to the resources will disappear and they will be garbage collected. There is no need to remember to set such struct members to nil.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnofeaturesonlybugs%2Froutines","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnofeaturesonlybugs%2Froutines","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnofeaturesonlybugs%2Froutines/lists"}