Documentation
¶
Index ¶
- Constants
- type Bus
- func (bus *Bus) ErrorHandlers(hdls ...ErrorHandler)
- func (bus *Bus) Handle(cmd Command) error
- func (bus *Bus) HandleAsync(cmd Command) error
- func (bus *Bus) Initialize(hdls ...Handler)
- func (bus *Bus) QueueBuffer(queueBuffer int)
- func (bus *Bus) Shutdown()
- func (bus *Bus) WorkerPoolSize(workerPoolSize int)
- type Command
- type ErrorBusIsShuttingDown
- type ErrorBusNotInitialized
- type ErrorHandler
- type ErrorInvalidCommand
- type Handler
Constants ¶
const ( // InvalidCommandError is a constant equivalent of the ErrorInvalidCommand error. InvalidCommandError = ErrorInvalidCommand("command: invalid command") // BusNotInitializedError is a constant equivalent of the ErrorBusNotInitialized error. BusNotInitializedError = ErrorBusNotInitialized("command: the bus is not initialized") // BusIsShuttingDownError is a constant equivalent of the ErrorBusIsShuttingDown error. BusIsShuttingDownError = ErrorBusIsShuttingDown("command: the bus is shutting down") )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bus ¶
type Bus struct {
// contains filtered or unexported fields
}
Bus is the only struct exported and required for the command bus usage. The Bus should be instantiated using the NewBus function.
func NewBus ¶
func NewBus() *Bus
NewBus instantiates the Bus struct. The Initialization of the Bus is performed separately (Initialize function) for dependency injection purposes.
func (*Bus) ErrorHandlers ¶
func (bus *Bus) ErrorHandlers(hdls ...ErrorHandler)
ErrorHandlers may optionally be provided. They will receive any error thrown during the command process.
func (*Bus) HandleAsync ¶
HandleAsync the command using the workers asynchronously.
func (*Bus) QueueBuffer ¶
QueueBuffer may optionally be provided to tweak the buffer size of the async commands queue. This value may have high impact on performance depending on the use case. It can only be adjusted *before* the bus is initialized. It defaults to 100.
func (*Bus) Shutdown ¶
func (bus *Bus) Shutdown()
Shutdown the command bus gracefully. *Async commands handled while shutting down will be disregarded*.
func (*Bus) WorkerPoolSize ¶
WorkerPoolSize may optionally be provided to tweak the worker pool size for async commands. It can only be adjusted *before* the bus is initialized. It defaults to the value returned by runtime.GOMAXPROCS(0).
type Command ¶
type Command interface {
ID() []byte
}
Command is the interface that must be implemented by any type to be considered a command.
type ErrorBusIsShuttingDown ¶
type ErrorBusIsShuttingDown string
ErrorBusIsShuttingDown is used when commands are handled but the bus is shutting down.
func (ErrorBusIsShuttingDown) Error ¶
func (e ErrorBusIsShuttingDown) Error() string
Error returns the string message of ErrorBusIsShuttingDown.
type ErrorBusNotInitialized ¶
type ErrorBusNotInitialized string
ErrorBusNotInitialized is used when commands are handled but the bus is not initialized.
func (ErrorBusNotInitialized) Error ¶
func (e ErrorBusNotInitialized) Error() string
Error returns the string message of ErrorBusNotInitialized.
type ErrorHandler ¶
ErrorHandler must be implemented for a type to qualify as an error handler.
type ErrorInvalidCommand ¶
type ErrorInvalidCommand string
ErrorInvalidCommand is used when invalid commands are handled.
func (ErrorInvalidCommand) Error ¶
func (e ErrorInvalidCommand) Error() string
Error returns the string message of ErrorInvalidCommand.