Source File
want_conn.go
Belonging Package
github.com/redis/go-redis/v9/internal/pool
package poolimport ()type wantConn struct {mu sync.RWMutex // protects ctx, done and sending of the resultctx context.Context // context for dial, cleared after delivered or canceledcancelCtx context.CancelFuncdone bool // true after delivered or canceledresult chan wantConnResult // channel to deliver connection or error}// getCtxForDial returns context for dial or nil if connection was delivered or canceled.func ( *wantConn) () context.Context {.mu.RLock()defer .mu.RUnlock()return .ctx}func ( *wantConn) ( *Conn, error) bool {.mu.Lock()defer .mu.Unlock()if .done {return false}.done = true.ctx = nil.result <- wantConnResult{cn: , err: }close(.result)return true}func ( *wantConn) () *Conn {.mu.Lock()var *Connif .done {select {case := <-.result:= .cndefault:}} else {close(.result)}.done = true.ctx = nil.mu.Unlock()return}func ( *wantConn) () bool {.mu.RLock()defer .mu.RUnlock()return !.done}type wantConnResult struct {cn *Connerr error}type wantConnQueue struct {mu sync.RWMutexitems []*wantConn}func newWantConnQueue() *wantConnQueue {return &wantConnQueue{items: make([]*wantConn, 0),}}func ( *wantConnQueue) ( *wantConn) {.mu.Lock()defer .mu.Unlock().items = append(.items, )}func ( *wantConnQueue) () (*wantConn, bool) {.mu.Lock()defer .mu.Unlock()if len(.items) == 0 {return nil, false}:= .items[0].items = .items[1:]return , true}func ( *wantConnQueue) () int {.mu.Lock()defer .mu.Unlock():= 0for len(.items) > 0 {if .items[0].isOngoing() {break}.items = .items[1:]++}return}
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |