Skip to content

Commit bcd8649

Browse files
committed
add findPendingCommand
1 parent 4a14f46 commit bcd8649

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

node_command.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,24 @@ var (
3939
ErrNodeTerminated = errors.New("node terminated")
4040
)
4141

42+
func findPendingCommand(
43+
pending map[commandKey]*pendingCommand,
44+
channel *Channel,
45+
systemID,
46+
componentID uint8,
47+
commandID uint32,
48+
) *pendingCommand {
49+
for key, p := range pending {
50+
if key.channel == channel &&
51+
key.targetSystem == systemID &&
52+
key.targetComp == componentID &&
53+
key.commandID == commandID {
54+
return p
55+
}
56+
}
57+
return nil
58+
}
59+
4260
// CommandOptions configures command sending behavior.
4361
type CommandOptions struct {
4462
// Channel to send the command on.
@@ -337,16 +355,7 @@ func (nc *nodeCommand) onEventFrame(evt *EventFrame) {
337355
}
338356

339357
nc.pendingMutex.RLock()
340-
var pending *pendingCommand
341-
for key, p := range nc.pending {
342-
if key.channel == evt.Channel &&
343-
key.targetSystem == evt.SystemID() &&
344-
key.targetComp == evt.ComponentID() &&
345-
key.commandID == commandID {
346-
pending = p
347-
break
348-
}
349-
}
358+
pending := findPendingCommand(nc.pending, evt.Channel, evt.SystemID(), evt.ComponentID(), commandID)
350359
nc.pendingMutex.RUnlock()
351360

352361
if pending == nil {

0 commit comments

Comments
 (0)