wsinternal

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Subscriber

type Subscriber interface {
	ID() string
	OnEventCallback(event any)
}

type Worker

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

Worker is used to handle work of the WorkerPool.

func NewWorker

func NewWorker(id int, channelBufferSize int, pool *WorkerPool) Worker

NewWorker creates a new Worker.

func (*Worker) Active

func (worker *Worker) Active() bool

func (*Worker) EnqueueEvent

func (worker *Worker) EnqueueEvent(event any)

func (*Worker) Start

func (worker *Worker) Start(_ context.Context) error

Start makes Worker start doing work.

type WorkerPool

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

WorkerPool is used to divide [Subscriber]s between [Worker]s. This prevents one Worker of being very busy.

func NewWorkerPool

func NewWorkerPool(maxWorkers int, channelBufferSize int) *WorkerPool

NewWorkerPool creates a new WorkerPool.

func (*WorkerPool) Active

func (pool *WorkerPool) Active() bool

Active checks if the WorkerPool is active by checking if any Worker is active.

func (*WorkerPool) AddSubscriber

func (pool *WorkerPool) AddSubscriber(sub Subscriber)

AddSubscriber adds a Subscriber to the WorkerPool.

func (*WorkerPool) EnqueueEvent

func (pool *WorkerPool) EnqueueEvent(event any)

EnqueueEvent puts an event on the Worker channels.

func (*WorkerPool) RemoveSubscriber

func (pool *WorkerPool) RemoveSubscriber(sub Subscriber)

RemoveSubscriber removes a Subscriber from the WorkerPool.

func (*WorkerPool) Start

func (pool *WorkerPool) Start()

Start starts [Worker]s of a WorkerPool if they weren't active yet.

func (*WorkerPool) Stop

func (pool *WorkerPool) Stop()

Stop stops all workers.

Jump to

Keyboard shortcuts

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