concurrent

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package concurrent contains some easy-to-use concurrent control utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	// Runner is a func need to be executed. It may return a list of new
	// actions. These actions will be executed after the current action had
	// finished
	Runner func() []Action

	// Dependencies for the current action. The current action will only be
	// executed after all dependencies had been finished
	Dependencies []Action
}

Action to be run concurrently

type ActionPool

type ActionPool interface {
	// Do an action. It's panic-free if using it correctly.
	// It will panic if you do an action in a closed pool.
	Do(Action)

	// Map returns a slice of result that applies `f` to every item of `input`.
	// The `ret` is in-order.
	Map(input []interface{}, f func(interface{}) interface{}) (ret []interface{})

	// Wait until all the actions had been finished.
	Wait()

	// Wait until all the actions had been finished, and close the pool.
	WaitAndClose()

	// Set a logger to output some err msg when panic. os.Stderr will be used
	// by default.
	SetLogger(io.Writer)
}

ActionPool is an action pool based on goroutines

func NewActionPool

func NewActionPool(maxConcurrent int) ActionPool

NewActionPool creates a new concurrent action pool. if maxConcurrent <= 0, then the real maxConcurrent will be runtime.NumCPU()

Jump to

Keyboard shortcuts

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