{"id":13413054,"url":"https://github.com/nikhilsaraf/go-tools","last_synced_at":"2025-03-14T19:31:11.044Z","repository":{"id":57491656,"uuid":"157481066","full_name":"nikhilsaraf/go-tools","owner":"nikhilsaraf","description":"A collection of tools for Golang","archived":false,"fork":false,"pushed_at":"2019-03-27T19:18:09.000Z","size":10,"stargazers_count":15,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-07-31T20:51:53.556Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/nikhilsaraf.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-11-14T02:53:08.000Z","updated_at":"2024-03-25T20:50:03.000Z","dependencies_parsed_at":"2022-08-30T23:22:06.012Z","dependency_job_id":null,"html_url":"https://github.com/nikhilsaraf/go-tools","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikhilsaraf%2Fgo-tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikhilsaraf%2Fgo-tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikhilsaraf%2Fgo-tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikhilsaraf%2Fgo-tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nikhilsaraf","download_url":"https://codeload.github.com/nikhilsaraf/go-tools/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221498712,"owners_count":16833053,"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":[],"created_at":"2024-07-30T20:01:32.878Z","updated_at":"2024-10-26T05:30:17.243Z","avatar_url":"https://github.com/nikhilsaraf.png","language":"Go","funding_links":[],"categories":["Goroutines","Relational Databases","Goroutines `goroutines的管理和使用`"],"sub_categories":["Advanced Console UIs","检索及分析资料库","Search and Analytic Databases","SQL 查询语句构建库"],"readme":"# go-tools\nA collection of tools for Golang, focusing on concurrency and goroutines\n\n[![Godoc](https://godoc.org/github.com/nikhilsaraf/go-tools?status.svg)](https://godoc.org/github.com/nikhilsaraf/go-tools)\n[![Go Report Card](https://goreportcard.com/badge/github.com/nikhilsaraf/go-tools)](https://goreportcard.com/report/github.com/nikhilsaraf/go-tools)\n[![Build Status](https://travis-ci.org/nikhilsaraf/go-tools.svg?branch=master)](https://travis-ci.org/nikhilsaraf/go-tools)\n[![License](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)](https://raw.githubusercontent.com/nikhilsaraf/go-tools/master/LICENSE)\n\nThe [multithreading](multithreading) library currently supports a `ThreadTracker` struct that allows you to easily manage goroutines.\n\n- Create new goroutines.\n- Wait for all goroutines to finish.\n- Set deferred functions to be executed after goroutines finish.\n- Easily handle panics inside goroutines with a panic handler.\n- Stop the `threadTracker` from receiving new functions.\n- Fetch the number of currently active goroutines.\n\n## Install\n\nInstall the package with:\n\n```bash\ngo get github.com/nikhilsaraf/go-tools/multithreading\n```\n\nImport it with:\n\n```go\nimport \"github.com/nikhilsaraf/go-tools/multithreading\"\n```\n\nand use `multithreading` as the package name inside the code.\n\n## Example\n\n```go\npackage main\n\nimport (\n  \"fmt\"\n  \"github.com/nikhilsaraf/go-tools/multithreading\"\n)\n\nfunc main() {\n  // create thread tracker instance\n  threadTracker := multithreading.MakeThreadTracker()\n\n  // start thread functions\n  for i := 0; i \u003c 10; i++ {\n    err := threadTracker.TriggerGoroutine(func(inputs []interface{}) {\n      // pass `i` as a value to the goroutine and read from `inputs`.\n      // this is needed to \"bind\" the variable to this goroutine.\n      value := inputs[0].(int)\n      \n      fmt.Printf(\"Goroutine #%d\\n\", value)\n    }, []interface{}{i})\n\n    if err != nil {\n      panic(err)\n    }\n  }\n\n  // wait for all threads to finish\n  threadTracker.Wait()\n  fmt.Printf(\"done\\n\")\n}\n\n```\n\nSample Output:\n```\nGoroutine #1\nGoroutine #2\nGoroutine #9\nGoroutine #0\nGoroutine #3\nGoroutine #7\nGoroutine #6\nGoroutine #4\nGoroutine #8\nGoroutine #5\ndone\n```\n\n## Test Examples\n[thread_tracker_test.go](/multithreading/thread_tracker_test.go)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikhilsaraf%2Fgo-tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnikhilsaraf%2Fgo-tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikhilsaraf%2Fgo-tools/lists"}