Runner

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Batch

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

Batch is a struct that represents a batch of Go routines.

func NewBatch

func NewBatch() *Batch

NewBatch creates a new batch of Go routines.

Returns:

  • *Batch: The new batch.

func (*Batch) Add

func (b *Batch) Add(identifier string, routine uc.MainFunc)

Add is a method of Batch that adds a Go routine to the batch.

Parameters:

  • identifier: The identifier of the Go routine.
  • routine: The Go routine to add to the batch.

Behaviors:

  • It ignores nil Go routines.
  • It replaces the Go routine if the identifier already exists in the batch.

func (*Batch) Clear

func (b *Batch) Clear()

Clear is a method of Batch that clears the batch.

func (*Batch) StartAll

func (b *Batch) StartAll()

StartAll is a function that starts all Go routines in the batch.

Parameters:

  • batch: A slice of pointers to the GRHandler instances that handle the Go routines.

func (*Batch) WaitAll

func (b *Batch) WaitAll() map[string]error

WaitAll is a function that waits for all Go routines in the batch to finish and returns a slice of errors that represent the error statuses of the Go routines.

Parameters:

  • batch: A slice of pointers to the GRHandler instances that handle the Go routines.

Returns:

  • map[string]error: A map of the error statuses of the Go routines.

type ErrAlreadyRunning

type ErrAlreadyRunning struct{}

ErrAlreadyRunning is an error type that represents an error where a process is already running.

func NewErrAlreadyRunning

func NewErrAlreadyRunning() *ErrAlreadyRunning

NewErrAlreadyRunning creates a new ErrAlreadyRunning error.

Returns:

  • *ErrAlreadyRunning: The new error.

func (*ErrAlreadyRunning) Error

func (e *ErrAlreadyRunning) Error() string

Error implements the error interface.

Message: "the process is already running"

type HandlerSend

type HandlerSend[T any] struct {
	// contains filtered or unexported fields
}

HandlerSend is a handler that, unlike HandlerSimple, whenever an error occurs, it is sent to the error channel instead of terminating the Go routine.

func NewHandlerSend

func NewHandlerSend[T any](routine uc.ErrorIfFunc[T]) *HandlerSend[T]

NewHandlerSend creates a new HandlerSend.

Parameters:

  • routine: The Go routine to run.

Returns:

  • *HandlerSend: A pointer to the HandlerSend that handles the result of the Go routine.

Behaviors:

  • The Go routine is not started automatically.
  • In routine, use *uc.ErrNoError to exit the Go routine as nil is used to signal that the function has finished successfully but the Go routine is still running.
  • If routine is nil, this function returns nil.

func (*HandlerSend[T]) Close

func (h *HandlerSend[T]) Close()

Close implements the Runner interface.

func (*HandlerSend[T]) IsClosed

func (h *HandlerSend[T]) IsClosed() bool

IsClosed implements the Runner interface.

func (*HandlerSend[T]) ReceiveErr

func (h *HandlerSend[T]) ReceiveErr() (error, bool)

ReceiveErr implements the Runner interface.

func (*HandlerSend[T]) Send

func (h *HandlerSend[T]) Send(msg T) bool

Send is a method of HandlerSend that sends a message to the Go routine. If the Go routine is not running, false is returned.

Parameters:

  • msg: The message to send.

Returns:

  • bool: True if the message is sent, false otherwise.

func (*HandlerSend[T]) Start

func (h *HandlerSend[T]) Start()

Start implements the Runner interface.

type HandlerSimple

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

HandlerSimple is a struct that represents a Go routine handler. It is used to handle the result of a Go routine.

func NewHandlerSimple

func NewHandlerSimple(routine uc.MainFunc) *HandlerSimple

NewHandlerSimple creates a new HandlerSimple.

Parameters:

  • routine: The Go routine to run.

Returns:

  • *HandlerSimple: A pointer to the HandlerSimple that handles the result of the Go routine.

Behaviors:

  • If routine is nil, this function returns nil.
  • The Go routine is not started automatically.
  • In routine, use *uc.ErrNoError to exit the Go routine as nil is used to signal that the function has finished successfully but the Go routine is still running.

func (*HandlerSimple) Close

func (h *HandlerSimple) Close()

Close implements the Runner interface.

func (*HandlerSimple) IsClosed

func (h *HandlerSimple) IsClosed() bool

IsClosed implements the Runner interface.

func (*HandlerSimple) ReceiveErr

func (h *HandlerSimple) ReceiveErr() (error, bool)

ReceiveErr implements the Runner interface.

func (*HandlerSimple) Start

func (h *HandlerSimple) Start()

Start implements the Runner interface.

type Runner

type Runner interface {
	// Start starts the runner. If it is already running, nothing happens.
	Start()

	// Close closes the runner. If it is not running, nothing happens.
	Close()

	// IsClosed returns true if the runner is closed, false otherwise.
	IsClosed() bool
}

Runner is an interface that defines the behavior of a type that can be started, stopped, and waited for.

type Sender

type Sender[T any] interface {
	// Send sends a message to the Buffer.
	//
	// Parameters:
	//   - msg: The message to send.
	//
	// Returns:
	//   - bool: False if the Buffer is closed, true otherwise.
	Send(msg T) bool
}

Sender is the interface that wraps the Send method.

type SenderRunner

type SenderRunner[T any] interface {
	Sender[T]
	Runner
}

SenderRunner is the interface that wraps the Send method and the Runner interface.

Jump to

Keyboard shortcuts

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