Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WaitAll ¶
func WaitAll(batch map[string]*HandlerSimple) 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:
- []error: A slice of errors that represent the error statuses of the Go routines.
Types ¶
type BatchBuilder ¶
type BatchBuilder struct {
// contains filtered or unexported fields
}
BatchBuilder is a struct that represents a Go routine batch builder. It is used to build a batch of Go routines and their handlers.
func (*BatchBuilder) Add ¶
func (b *BatchBuilder) Add(identifier string, routine uc.MainFunc)
Add is a method of BatchBuilder 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.
func (*BatchBuilder) Build ¶
func (b *BatchBuilder) Build() map[string]*HandlerSimple
Build is a method of BatchBuilder that builds the batch of Go routines and their handlers.
Returns:
- []*HandlerSimple: A slice of pointers to the HandlerSimple instances that handle the Go routines.
All Go routines are automatically run when this method is called. Finally, the batch is cleared after the Go routines are built.
func (*BatchBuilder) Clear ¶
func (b *BatchBuilder) Clear()
Clear is a method of BatchBuilder that clears the batch of 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 returns the error message: "the process is already running".
Returns:
- string: The error message.
type ExecuteMsgFunc ¶
ExecuteMsgFunc is a function type that executes a message.
Parameters:
- msg: The message to execute.
Returns:
- error: An error if the message cannot be executed.
func NewRedirector ¶
func NewRedirector[T any](from <-chan T, to chan<- T) (ExecuteMsgFunc[T], error)
NewRedirector creates a new redirector that redirects messages from one channel to another.
Parameters:
- from: The channel to redirect messages from.
- to: The channel to redirect messages to.
Returns:
- ExecuteMsgFunc: The function that redirects messages.
- error: An error of type *ers.ErrInvalidParameter if from or to are nil.
type HandlerSend ¶
type HandlerSend[T any] struct { // contains filtered or unexported fields }
HandlerSend is a struct that represents a Go routine handler. It is used to handle the result of a Go routine.
func NewHandlerSend ¶
func NewHandlerSend[T any](routine ExecuteMsgFunc[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 *ers.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 (*HandlerSend[T]) Close ¶
func (h *HandlerSend[T]) Close()
Close closes the runner.
Behaviors:
- If the Go routine is not running, this method does nothing.
func (*HandlerSend[T]) GetErrChannel ¶
func (h *HandlerSend[T]) GetErrChannel() <-chan error
GetErrChannel is a method of HandlerSend that returns the error status of the Go routine.
Returns:
- error: The error status of the Go routine.
func (*HandlerSend[T]) IsRunning ¶
func (h *HandlerSend[T]) IsRunning() bool
IsRunning returns whether the runner is running.
Returns:
- bool: True if the runner is running, false otherwise.
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() error
Start is a method of HandlerSend that starts the Go routine.
Returns:
- error: An error if the Go routine cannot be started.
Errors:
- *ErrAlreadyRunning: The Go routine is already running.
- *ers.ErrInvalidType: The status of the Go routine is invalid.
Behaviors:
- If the Go routine is stopped, it will be started.
- If the Go routine is running, the error *ErrAlreadyRunning is returned.
- If the Go routine is not initialized, the error *ErrNilValue is returned.
func (*HandlerSend[T]) Wait ¶
func (h *HandlerSend[T]) Wait()
Wait is a method of HandlerSend that waits for the Go routine to finish.
Behaviors:
- If the Go routine is not running, this method does nothing.
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:
- The Go routine is not started automatically.
- In routine, use *ers.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 closes the runner.
Behaviors:
- If the Go routine is not running, this method does nothing.
func (*HandlerSimple) GetErrChannel ¶
func (h *HandlerSimple) GetErrChannel() <-chan error
GetErrChannel is a method of HandlerSimple that returns the error status of the Go routine.
Returns:
- error: The error status of the Go routine.
func (*HandlerSimple) IsRunning ¶
func (h *HandlerSimple) IsRunning() bool
IsRunning returns whether the runner is running.
Returns:
- bool: True if the runner is running, false otherwise.
func (*HandlerSimple) Start ¶
func (h *HandlerSimple) Start() error
Start is a method of HandlerSimple that starts the Go routine.
Returns:
- error: An error if the Go routine cannot be started.
Errors:
- *ErrAlreadyRunning: The Go routine is already running.
- *ers.ErrInvalidType: The status of the Go routine is invalid.
Behaviors:
- If the Go routine is stopped, it will be started.
- If the Go routine is running, the error *ErrAlreadyRunning is returned.
- If the Go routine is not initialized, the error *ErrNilValue is returned.
func (*HandlerSimple) Wait ¶
func (h *HandlerSimple) Wait()
Wait is a method of HandlerSimple that waits for the Go routine to finish.
Behaviors:
- If the Go routine is not running, this method does nothing.
type Runner ¶
type Runner interface { // Start starts the runner. // // Returns: // - error: An error of type *ErrAlreadyRunning if the runner is already running. // or any other error if the runner could not be started. Start() error // Wait waits for the runner to finish. Wait() // Close closes the runner. Close() // IsRunning returns true if the runner is running, false otherwise. IsRunning() bool }
Runner is an interface that defines the behavior of a type that can be started, stopped, and waited for.