Source File
req_map.go
Belonging Package
github.com/gotd/td/internal/pool
package pool
import (
)
type reqKey int64
type reqMap struct {
m map[reqKey]chan *poolConn
mux sync.Mutex
_ [4]byte
nextRequest 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 *poolConn
var reqKey
for , = 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. |