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()
}