Skip to content

Commit

Permalink
removed unnecessary checks from command handler registration
Browse files Browse the repository at this point in the history
  • Loading branch information
psrvere committed Dec 22, 2024
1 parent de57154 commit 8076e44
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions internal/commandhandler/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ type Registry struct {
}

var (
ErrMaxCmdHandlersReached = errors.New("maximum number of command handlers reached")
ErrCmdHandlerNotFound = errors.New("command handler not found")
ErrCmdHandlerNotBase = errors.New("command handler is not a BaseCommandHandler")
ErrMaxCmdHandlersReached = errors.New("maximum number of command handlers reached")
ErrCmdHandlerNotFound = errors.New("command handler not found")
ErrCmdHandlerNotBase = errors.New("command handler is not a BaseCommandHandler")
ErrCmdHandlerResponseChanNil = errors.New("command handler response channel is nil")
)

func NewRegistry(maxClients uint32, sm *shard.ShardManager) *Registry {
Expand All @@ -37,15 +38,12 @@ func (m *Registry) RegisterCommandHandler(cmdHandler *BaseCommandHandler) error
return ErrMaxCmdHandlersReached
}

responseChan := cmdHandler.responseChan
preprocessingChan := cmdHandler.preprocessingChan

if responseChan != nil && preprocessingChan != nil {
m.ShardManager.RegisterCommandHandler(cmdHandler.ID(), responseChan, preprocessingChan) // TODO: Change responseChan type to ShardResponse
} else if responseChan != nil && preprocessingChan == nil {
m.ShardManager.RegisterCommandHandler(cmdHandler.ID(), responseChan, nil)
if cmdHandler.responseChan == nil {
return ErrCmdHandlerResponseChanNil
}

m.ShardManager.RegisterCommandHandler(cmdHandler.ID(), cmdHandler.responseChan, cmdHandler.preprocessingChan)

m.activeCmdHandlers.Store(cmdHandler.ID(), cmdHandler)

m.numCmdHandlers.Add(1)
Expand Down

0 comments on commit 8076e44

Please sign in to comment.