cocurrent

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2022 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Cocurrent - 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/cocurrent

Getting Started

func TestCocurrent(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

This section is empty.

Functions

This section is empty.

Types

type Cocurrent

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

Cocurrent is a concurrent object

func New

func New(limit int) *Cocurrent

New creates a new cocurrent object

func (*Cocurrent) Add

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

Add adds a new task to the cocurrent object

func (*Cocurrent) Done

func (c *Cocurrent) Done()

Done removes a task from the cocurrent object

func (*Cocurrent) Wait

func (c *Cocurrent) 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
⌂ 换网址