Remove removes the specified callback function from the callback linked list Parameters: - handler: Handler identifier of the callback to be removed - key: Unique identifier key of the callback to be removed Note: If no matching callback is found, this method has no effect
(handler, key any)
| 59 | // |
| 60 | // Note: If no matching callback is found, this method has no effect |
| 61 | func (t *callbacks) Remove(handler, key any) { |
| 62 | var prev *callbackNode |
| 63 | |
| 64 | // Traverse linked list to find the node to be removed |
| 65 | for callback := t.first; callback != nil; prev, callback = callback, callback.next { |
| 66 | // Found matching node |
| 67 | if callback.handler == handler && callback.key == key { |
| 68 | if t.first == callback { |
| 69 | // If it's the first node, update first pointer |
| 70 | t.first = callback.next |
| 71 | } else if prev != nil { |
| 72 | // If it's a middle node, update the next pointer of the previous node |
| 73 | prev.next = callback.next |
| 74 | } |
| 75 | |
| 76 | if t.last == callback { |
| 77 | // If it's the last node, update last pointer |
| 78 | t.last = prev |
| 79 | } |
| 80 | |
| 81 | // Return immediately after finding and removing |
| 82 | return |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | // Invoke executes all registered callback functions in the linked list |
| 88 | // Executes each callback in the order they were added |