Limits the number of goroutines that are allowed to run concurrently

Related tags

Goroutines goccm
Overview

Golang Concurrency Manager Build Status

Golang Concurrency Manager package limits the number of goroutines that are allowed to run concurrently.

Installation

Run the following command to install this package:

$ go get -u github.com/zenthangplus/goccm

Example

package main

import (
    "fmt"
    "goccm"
    "time"
)

func main()  {
    // Limit 3 goroutines to run concurrently.
    c := goccm.New(3)
    
    for i := 1; i <= 10; i++ {
    	
        // This function have to call before any goroutine
        c.Wait()
        
        go func(i int) {
            fmt.Printf("Job %d is running\n", i)
            time.Sleep(2 * time.Second)
            
            // This function have to when a goroutine has finished
            // Or you can use `defer c.Done()` at the top of goroutine.
            c.Done()
        }(i)
    }
    
    // This function have to call to ensure all goroutines have finished 
    // after close the main program.
    c.WaitAllDone()
}

List of supported functions

package main

import "goccm"

func main() {
    // Create the concurrency manager
    // The first argument is the maximum number of goroutines to run concurrently.
    c := goccm.New(10)
    
    // Wait until a slot is available for the new goroutine.
    c.Wait()
    
    // Mark a goroutine as finished
    c.Done()
    
    // Wait for all goroutines are done
    c.WaitAllDone()
    
    // Close the manager manually
    c.Close()
    
    // Returns the number of goroutines which are running
    c.RunningCount()
}
Issues
  • Simplify management

    Simplify management

    • added go.mod file
    • simplify channel management
      • use struct{} as signal instead of interface{}
      • replace need for atomic counter
      • move controller functionality within Done
    • add benchmark concurrency test
    opened by chr1sto14 6
  • request

    request

    goccm needs to export the concurrencyManager for a regular func to work: e.g.

    func main() { var ccm = goccm.New(10) for int i = 0; i < 50; i++ { ccm.Wait() go myfunc(ccm) } // .... ccm.WaitAllDone() }

    func myfunc(ccm *T) { defer ccm.Done() // doing some work .... }

    opened by zeyujiang 0
  • Invalid Tags for Golang Project.

    Invalid Tags for Golang Project.

    Hi. I saw that the tags you are using is 2 digits (x.x) while golang requires 3 digits in the format of vmajor.minor.patch.

    Will you be able to add tags for v1.1.0? Then my golang can download your project with the correct tags. Otherwise golang will default to pseudo tags which is non-human readable.

    Currently if I downloaded you tag from latest branch, it will looks like

    module github.com/iqdf/myrepo
    
    go 1.14
    
    require (
      github.com/zenthangplus/goccm v0.0.0-20211005163543-2f2e522aca15
    )
    
    opened by iqDF 0
  • simplyfying manager, added go.mod and check for task execution in tests

    simplyfying manager, added go.mod and check for task execution in tests

    inspired from: @chr1sto14

    1. Simplified manager, no need to fill the channel on initialisation
    2. added check in tests to verify if all tasks are being executed.
    3. changed to go module structure
    opened by chiamakacha 4
Releases(1.1)
Owner
Bui Thang
Don’t wait for the perfect moment, take the moment and make it perfect.
Bui Thang
errgroup with goroutine worker limits

neilotoole/errgroup neilotoole/errgroup is a drop-in alternative to Go's wonderful sync/errgroup but limited to N goroutines. This is useful for inter

Neil O'Toole 128 Jun 28, 2022
👷 Library for safely running groups of workers concurrently or consecutively that require input and output through channels

Examples Quickstart Multiple Go Workers Passing Fields Getting Started Pull in the dependency go get github.com/catmullet/go-workers Add the import to

Robert Catmull 144 Jun 2, 2022
Floc: Orchestrate goroutines with ease.

go-floc Floc: Orchestrate goroutines with ease. The goal of the project is to make the process of running goroutines in parallel and synchronizing the

Andrew Bashkatov 250 Jun 18, 2022
Simply way to control goroutines execution order based on dependencies

Goflow Goflow is a simply package to control goroutines execution order based on dependencies. It works similar to async.auto from node.js async packa

Kamil Drazkiewicz 194 Jun 20, 2022
gpool - a generic context-aware resizable goroutines pool to bound concurrency based on semaphore.

gpool - a generic context-aware resizable goroutines pool to bound concurrency. Installation $ go get github.com/sherifabdlnaby/gpool import "github.c

Sherif Abdel-Naby 84 Feb 21, 2022
Routines was a fixed number thread pool to process the user task, and it would respawn a corresponding new thread when panic

Routines Routines was a fixed number thread pool to process the user task, and it would respawn a corresponding new thread when panic. It supports the

hulk 12 Dec 16, 2021
Run functions in parallel :comet:

Parallel fn Run functions in parallel. Limit the number of goroutines running at the same time. Installation go get -u github.com/rafaeljesus/parallel

Rafael Jesus 33 Mar 5, 2022
Run tasks concurrently with limits

Workerpool Package workerpool implements a concurrency limiting worker pool. Worker routines are spawned on demand as tasks are submitted. This packag

Cilium 18 Jun 8, 2022
Guess-number-game - Computer thoughts of some integer number, you must guess it with limited number of attempts

Guess number game Rules Computer has thought of some integer number. You must guess it, you have numberOfAttempts attempts. How to run Just type in co

Nikita Shamaev 0 Dec 31, 2021
SizedWaitGroup has the same role and close to the same API as the Golang sync.WaitGroup but it adds a limit on the amount of goroutines started concurrently.

SizedWaitGroup SizedWaitGroup has the same role and API as sync.WaitGroup but it adds a limit of the amount of goroutines started concurrently. SizedW

Rémy Mathieu 320 Jun 20, 2022
Utility to restrict which package is allowed to import another package.

go-import-rules Utility to restrict which package is allowed to import another package. This tool will read import-rules.yaml or import-rules.yml in t

PAYFAZZ 0 Jan 7, 2022
PiHex Library, written in Go, generates a hexadecimal number sequence in the number Pi in the range from 0 to 10,000,000.

PiHex PiHex Library generates a hexadecimal number sequence in the number Pi in the range from 0 to 1.0e10000000. To calculate using "Bailey-Borwein-P

Eduard 15 Apr 28, 2022
A simple command line tool using which you can skip phone number based SMS verification by using a temporary phone number that acts like a proxy.

Fake-SMS A simple command line tool using which you can skip phone number based SMS verification by using a temporary phone number that acts like a pr

Narasimha Prasanna HN 692 Jun 30, 2022
MNA - stands for mobile number assignment - a small zero external dependency golang library that is used to identify mobile number assignment in tanzania

MNA - stands for mobile number assignment - a small zero external dependency golang library that is used to identify mobile number assignment in tanzania

TECHCRAFT TECHNOLOGIES LIMITED 8 Nov 29, 2021
A tool to determine the highest version number that's smaller than a target version number

semver-highest A tool to determine the highest version number that's smaller than a target version number. Installation go install github.com/marten-s

Marten Seemann 1 Oct 13, 2021
A simple command line tool using which you can skip phone number based SMS verification by using a temporary phone number that acts like a proxy

Fake-SMS A simple command line tool using which you can skip phone number based SMS verification by using a temporary phone number that acts like a pr

Narasimha Prasanna HN 687 Jun 22, 2022
Converts a number to its English counterpart. Uses arbitrary precision; so a number of any size can be converted.

Converts a number to its English counterpart. Uses arbitrary precision; so a number of any size can be converted.

null 0 Dec 14, 2021
Iran National Id, Bank Card Number, Mobile Number Validator for golang

Iran IDValidator Iran National Id, Bank Card Number, Mobile Number Validator for golang Installation go get -u github.com/mohammadv184/idvalidator Us

Mohammad Abbasi 1 Dec 20, 2021
Divide (distribute) the given number (n) into number (p) of parts randomly,

Number Split Randomly The sample code written in Go lang Executables This repo already have executables for Linux and windows, after clone the repo ju

Jobin Jose 0 Feb 4, 2022
Using NFP (Number Format Parser) you can get an Abstract Syntax Tree (AST) from Excel number format expression

NFP (Number Format Parser) Using NFP (Number Format Parser) you can get an Abstract Syntax Tree (AST) from Excel number format expression. Installatio

fossabot 0 Feb 4, 2022
Toy project to test golang toolset, using as pretext the "cyclic number" problem (famous 142857 number)

go-cyclic-number Toy project to test golang toolset, using as pretext the "cyclic number" problem (famous 142857 number) First version: https://github

A. M. Cajal 0 Feb 12, 2022
run/stop goroutines/tasks securely, recursively

grunner - run/stop goroutines/tasks securely, recursively. s1 := grunner.New() s1.Defer(func() { fmt.Println("s1 stopped 2") }) s1.Defer(func() {

vogo 0 Apr 22, 2022
errgroup with goroutine worker limits

neilotoole/errgroup neilotoole/errgroup is a drop-in alternative to Go's wonderful sync/errgroup but limited to N goroutines. This is useful for inter

Neil O'Toole 128 Jun 28, 2022
Golang io.Reader and io.Writer but with limits

LimitIO io.Reader and io.Writer with limit.

LI Zhennan 68 May 11, 2022
Ransomware: a type of malware that prevents or limits users from accessing their system

Ransomware Note 1: This project is purely academic, use at your own risk. I do not encourage in any way the use of this software illegally or to attac

null 1 Nov 17, 2021
GitHub Rate Limits Prometheus exporter. Works with both App and PAT credentials

Github Rate Limit Prometheus Exporter A prometheus exporter which scrapes GitHub API for the rate limits used by PAT/GitHub App. Helm Chart with value

Kostiantyn Kulbachnyi 5 Jun 22, 2022
Pacemaker - Rate limit library. Currently implemented rate limits are

PaceMaker Rate limit library. Currently implemented rate limits are Fixed window

Marquitos 2 Apr 2, 2022
A package to allow one to concurrently go through a filesystem with ease

skywalker Skywalker is a package to allow one to concurrently go through a filesystem with ease. Features Concurrency BlackList filtering WhiteList fi

Will Dixon 80 Jun 18, 2022
👷 Library for safely running groups of workers concurrently or consecutively that require input and output through channels

Examples Quickstart Multiple Go Workers Passing Fields Getting Started Pull in the dependency go get github.com/catmullet/go-workers Add the import to

Robert Catmull 144 Jun 2, 2022