workerjuice

package
v1.11.8 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: MIT Imports: 1 Imported by: 1

Documentation

Overview

Description: This file contains the implementation of a simple semaphore. It is used to control the number of resources that can be accessed concurrently.

Description: This package provides a worker pool implementation for concurrency limiting. It includes a Pool interface and a Pool struct that implements the interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

type Pool interface {
	AddWorker()
	RemoveWorker()
	WorkerCount() int
	Wait()
	Close()
}

Create an interface for the Pool struct.

func CreateEmptyPool

func CreateEmptyPool(maxWorkers uint) Pool

CreateEmptyPool creates a new worker pool with the specified maximum number of workers.

It returns a pointer to the created Pool.

type SemaphoreInterface

type SemaphoreInterface interface {
	// Acquire acquires a resource controlled by the semaphore.
	Acquire()
	// Release releases a resource controlled by the semaphore.
	Release()
	// Wait blocks until all resources have been released.
	Wait()
}

SemaphoreInterface defines the methods that a semaphore should implement.

func NewSemaphore

func NewSemaphore(concurrency int) SemaphoreInterface

NewSemaphore creates a new Semaphore with the specified concurrency level.

type Worker

type Worker struct{}

Worker represents a worker in a worker pool.

Jump to

Keyboard shortcuts

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