concurrency

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2023 License: MIT Imports: 3 Imported by: 1

README

Concurrency - A Simple Goroutine Limit Pool

PkgGoDev Build Status Go Report Card Coverage Status GitHub issues Release

Installation

To install the package, run:

go get github.com/go-zoox/concurrency

Getting Started

func TestConcurrency(t *testing.T) {
	c := New(2)

	for i := 0; i < 4; i++ {
		fmt.Println("Adding task", i)
		c.Add(func(args ...interface{}) {
			index := args[0].(int)

			fmt.Println("task", index, time.Now())
			time.Sleep(3 * time.Second)

			if index == 0 {
				panic("panic error for task 0")
			}
		}, i)
	}

	c.Wait()
}

Inspired by

License

GoZoox is released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version = "1.2.0"

Version is the current version of the package.

Functions

This section is empty.

Types

type Concurrency

type Concurrency struct {
	// contains filtered or unexported fields
}

Concurrency is a concurrent object

func New

func New(limit int) *Concurrency

New creates a new concurrency object

func (*Concurrency) Add

func (c *Concurrency) Add(task func(args ...interface{}), args ...interface{})

Add adds a new task to the concurrency object

func (*Concurrency) Done

func (c *Concurrency) Done()

Done removes a task from the concurrency object

func (*Concurrency) Wait

func (c *Concurrency) Wait()

Wait waits for all tasks to be done

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL