ProcessOnPut calls all OnPut hooks in order. The first hook that returns shouldRemove=true or shouldPool=false will stop processing.
(ctx context.Context, conn *Conn)
| 93 | // ProcessOnPut calls all OnPut hooks in order. |
| 94 | // The first hook that returns shouldRemove=true or shouldPool=false will stop processing. |
| 95 | func (phm *PoolHookManager) ProcessOnPut(ctx context.Context, conn *Conn) (shouldPool bool, shouldRemove bool, err error) { |
| 96 | // Copy slice reference while holding lock (fast) |
| 97 | phm.hooksMu.RLock() |
| 98 | hooks := phm.hooks |
| 99 | phm.hooksMu.RUnlock() |
| 100 | |
| 101 | shouldPool = true // Default to pooling the connection |
| 102 | |
| 103 | // Call hooks without holding lock (slow operations) |
| 104 | for _, hook := range hooks { |
| 105 | hookShouldPool, hookShouldRemove, hookErr := hook.OnPut(ctx, conn) |
| 106 | |
| 107 | if hookErr != nil { |
| 108 | return false, true, hookErr |
| 109 | } |
| 110 | |
| 111 | // If any hook says to remove or not pool, respect that decision |
| 112 | if hookShouldRemove { |
| 113 | return false, true, nil |
| 114 | } |
| 115 | |
| 116 | if !hookShouldPool { |
| 117 | shouldPool = false |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | return shouldPool, false, nil |
| 122 | } |
| 123 | |
| 124 | // ProcessOnRemove calls all OnRemove hooks in order. |
| 125 | func (phm *PoolHookManager) ProcessOnRemove(ctx context.Context, conn *Conn, reason error) { |