register adds or replaces the callback associated with id. Re-registering an existing id overwrites the previous callback in place; new ids are appended to the invocation order.
(id string, fn func() error)
| 256 | // an existing id overwrites the previous callback in place; new ids are |
| 257 | // appended to the invocation order. |
| 258 | func (h *onCloseHooks) register(id string, fn func() error) { |
| 259 | h.mu.Lock() |
| 260 | defer h.mu.Unlock() |
| 261 | if h.hooks == nil { |
| 262 | h.hooks = make(map[string]func() error) |
| 263 | } |
| 264 | if _, exists := h.hooks[id]; !exists { |
| 265 | h.order = append(h.order, id) |
| 266 | } |
| 267 | h.hooks[id] = fn |
| 268 | } |
| 269 | |
| 270 | // unregister removes the callback associated with id, if any. It is kept |
| 271 | // for API symmetry with register so future callers (e.g. dynamic hook |
no outgoing calls