runner

package
v0.1.16 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// AlreadyRunning is the error that is returned when the process is already running.
	AlreadyRunning error
)

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. Never returns nil.

func (*Batch) Add

func (b *Batch) Add(identifier string, routine func() error)

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 DoFunc added in v0.1.11

type DoFunc[I, O any] func(ctx context.Context, elem I) (O, error)

DoFunc is a function that defines the behavior of a Go routine.

Parameters:

  • ctx: The context of the Go routine.
  • elem: The element to process.

Returns:

  • O: The result of the Go routine.
  • error: The error status of the Go routine.

type ErrPanic added in v0.1.11

type ErrPanic struct {
	// Value is the value that caused the panic.
	Value any
}

ErrPanic represents an error when a panic occurs.

func NewErrPanic added in v0.1.11

func NewErrPanic(value any) *ErrPanic

NewErrPanic creates a new ErrPanic error.

Parameters:

  • value: The value that caused the panic.

Returns:

  • *ErrPanic: A pointer to the newly created ErrPanic. Never returns nil.

func (ErrPanic) Error added in v0.1.11

func (e ErrPanic) Error() string

Error implements the error interface.

Message: "panic: {value}"

type Handler added in v0.1.11

type Handler[O any] struct {
	// Data is the result of the Go routine.
	Data O

	// Err is the error status of the Go routine.
	Err error
}

Handler is a struct that represents a Go routine handler.

func ExecuteBatch added in v0.1.11

func ExecuteBatch[I, O any](ctx context.Context, elems iter.Seq[I], do_fn DoFunc[I, O]) []Handler[O]

ExecuteBatch executes a batch of Go routines.

Parameters:

  • ctx: The context of the batch.
  • elems: The elements to process.
  • do_fn: The function that defines the behavior of the Go routines.

Returns:

  • []Handler[O]: The results of the Go routines.

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 func() error) (*HandlerSimple, bool)

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.
  • bool: True if the HandlerSimple was created successfully, false otherwise.

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.

Jump to

Keyboard shortcuts

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