mongo-go-driver

m12發表於2019-04-20
// NewPool creates a new pool that will hold size number of idle connections
// and will create a max of capacity connections. It will use the provided
// options.
func NewPool(addr address.Address, size, capacity uint64, opts ...Option) (Pool, error) {
    if size > capacity {
        return nil, ErrSizeLargerThanCapacity
    }
    p := &pool{
        address:    addr,
        conns:      make(chan *pooledConnection, size),
        generation: 0,
        sem:        semaphore.NewWeighted(int64(capacity)),
        connected:  disconnected,
        capacity:   capacity,
        inflight:   make(map[uint64]*pooledConnection),
        opts:       opts,
    }
    return p, nil
}

這個https://github.com/mongodb/mongo-go-driver/blob/master/x/network/connection/pool.go 這個是怎麼用的,官方驅動現在穩定了嗎?

更多原創文章乾貨分享,請關注公眾號
  • mongo-go-driver
  • 加微信實戰群請加微信(註明:實戰群):gocnio