You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: connpool.go
    path of file: ./repos/scan4all/vendor/github.com/projectdiscovery/retryabledns
    
    the code of the file until where you have to start completion: package retryabledns

import (
	"container/heap"
	"context"
	"fmt"
	"net"
	"time"

	"github.com/miekg/dns"
)

type ConnPool struct {
	items      map[*dns.Conn]bool
	newArrival chan *waitingClient
	finished   chan *dns.Conn
	clients    clientQueue
	cancel     context.CancelFunc
	resolver   NetworkResolver
}

func NewConnPool(resolver NetworkResolver, poolSize int) (*ConnPool, error) {
    
func (cp *ConnPool) coordinate(ctx context.Context) {
	for {
		select {
		case <-ctx.Done():
			return
		case client := <-cp.newArrival:
			heap.Push(&cp.clients, client)
		case conn := <-cp.finished:
			cp.items[conn] = false
		}
		for conn, inUse := range cp.items {
			if !inUse && len(cp.clients) > 0 {
				cp.items[conn] = true
				client := heap.Pop(&cp.clients).(*waitingClient)
				select {
				case client.returnCh <- conn:
				case <-client.doneCh:
					cp.items[conn] = false
				case <-ctx.Done():
					return
				}
			}
		}
	}
}