Source File
req_map.go
Belonging Package
github.com/gotd/td/internal/pool
package poolimport ()type reqKey int64type reqMap struct {m map[reqKey]chan *poolConnmux sync.Mutex_ [4]bytenextRequest atomic.Int64}func () *reqMap {return &reqMap{m: map[reqKey]chan *poolConn{},}}func ( *reqMap) () ( reqKey, chan *poolConn) {= reqKey(.nextRequest.Inc())= make(chan *poolConn, 1).mux.Lock().m[] =.mux.Unlock()return ,}func ( *reqMap) ( *poolConn) bool {.mux.Lock()if len(.m) < 1 { // no requests.mux.Unlock()return false}var chan *poolConnvar reqKeyfor , = range .m { // Get one from map.break}delete(.m, ) // Remove from pending requests..mux.Unlock()if == nil {panic("unreachable: channel can't be nil due to map not empty")}<-close()return true}func ( *reqMap) ( reqKey) {.mux.Lock()delete(.m, ).mux.Unlock()}
![]() |
The pages are generated with Golds v0.6.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 @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |