concurrency

package module
v0.0.0-...-3a9469f Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoLimit = 0 // NoLimit denotes no limit imposed on the concurrency
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Limit

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

Limit provides a generic concurrency / work limiter

func New

func New(n int) (l *Limit)

New instantiates a new limiter with the given maximum concurrency

func (*Limit) Add

func (l *Limit) Add()

Add adds a new worker / task to be taken into account

func (*Limit) Done

func (l *Limit) Done()

Done releases a worker / task back into the pool

type MemFile

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

MemFile denotes an in-memory abstraction of an underlying file, acting as a buffer (drawing memory from a pool)

func NewMemFile

func NewMemFile(r ReadWriteSeekCloser, pool MemPool) (*MemFile, error)

NewMemFile instantiates a new in-memory file buffer

func (*MemFile) Close

func (m *MemFile) Close() error

Close fulfils the underlying io.Closer interface (returning the buffer to the pool)

func (*MemFile) Data

func (m *MemFile) Data() []byte

Data provides zero-copy access to the underlying data of the MemFile

func (*MemFile) Read

func (m *MemFile) Read(p []byte) (n int, err error)

Read fulfils the io.Reader interface (reading len(p) bytes from the buffer)

func (*MemFile) Seek

func (m *MemFile) Seek(offset int64, whence int) (int64, error)

Seek fulfils the io.Seeker interface (seeking to a designated position)

func (*MemFile) Stat

func (m *MemFile) Stat() (fs.FileInfo, error)

Stat return the (stub) Stat element providing the length of the underlying data

func (*MemFile) Write

func (m *MemFile) Write(p []byte) (n int, err error)

Write fulfils the io.Writer interface (writing len(p) bytes to the buffer)

type MemPool

type MemPool interface {
	Get(size int) (elem []byte)
	Put(elem []byte)
}

MemPool denotes a generic memory buffer pool

type MemPoolGCable

type MemPoolGCable interface {
	Clear()

	MemPool
}

MemPoolGCable denotes a generic memory buffer pool that can be "cleaned", i.e. that allows making all resources available for garbage collection

type MemPoolLimit

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

MemPoolLimit provides a channel-based memory buffer pool (limiting the number of resources and allowing for cleanup)

func NewMemPool

func NewMemPool(n int) *MemPoolLimit

NewMemPool instantiates a new memory pool that manages bytes slices

func (*MemPoolLimit) Clear

func (p *MemPoolLimit) Clear()

Clear releases all pool resources and makes them available for garbage collection

func (*MemPoolLimit) Get

func (p *MemPoolLimit) Get(size int) (elem []byte)

Get retrieves a memory element (already performing the type assertion)

func (*MemPoolLimit) Put

func (p *MemPoolLimit) Put(elem []byte)

Put returns a memory element to the pool, resetting its size to capacity in the process

type MemPoolNoLimit

type MemPoolNoLimit struct {
	sync.Pool
}

MemPoolNoLimit wraps a standard sync.Pool (no limit to resources)

func NewMemPoolNoLimit

func NewMemPoolNoLimit() *MemPoolNoLimit

NewMemPoolNoLimit instantiates a new memory pool that manages bytes slices of arbitrary capacity

func (*MemPoolNoLimit) Get

func (p *MemPoolNoLimit) Get(size int) (elem []byte)

Get retrieves a memory element (already performing the type assertion)

func (*MemPoolNoLimit) Put

func (p *MemPoolNoLimit) Put(elem []byte)

Put returns a memory element to the pool, resetting its size to capacity in the process

type ReadWriteSeekCloser

type ReadWriteSeekCloser interface {
	Stat() (fs.FileInfo, error)

	io.Reader
	io.Writer
	io.Seeker
	io.Closer
}

ReadWriteSeekCloser provides an interface to all the wrapped interfaces in one instance

Jump to

Keyboard shortcuts

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