diff options
Diffstat (limited to 'jsonrpc/client/message_dispatcher.go')
-rw-r--r-- | jsonrpc/client/message_dispatcher.go | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/jsonrpc/client/message_dispatcher.go b/jsonrpc/client/message_dispatcher.go index dab75ca..9177f6e 100644 --- a/jsonrpc/client/message_dispatcher.go +++ b/jsonrpc/client/message_dispatcher.go @@ -40,17 +40,18 @@ func (c *messageDispatcher[K, V]) length() int { return len(c.chans) } -// disptach Disptaches the msg to the channel with the given key -func (c *messageDispatcher[K, V]) disptach(key K, msg V) error { +// dispatch Disptaches the msg to the channel with the given key +func (c *messageDispatcher[K, V]) dispatch(key K, msg V) error { c.Lock() - defer c.Unlock() + ch, ok := c.chans[key] + c.Unlock() - if ch, ok := c.chans[key]; ok { - ch <- msg - return nil + if !ok { + return fmt.Errorf("Channel not found") } - return fmt.Errorf("Channel not found") + ch <- msg + return nil } // unregister Unregisters the channel with the provided key |