pool.go
func (pool *WriterPool) Get(w io.Writer) (writer io.Writer, release func()) {
	// don't export a ThrottlerWriter to prevent users changing the rate
	// and expecting their change to be respected, since we might modify
	// the rate under their feet

	// make the initial rate be 0, the actual rate is
	// set in the call to `setSharedRates`.
	wr := ThrottledWriter(w, 0, pool.maxBurst)

	pool.mu.Lock()
	pool.givenOut[wr] = struct{}{}
	pool.setSharedRates()
	pool.mu.Unlock()

	return wr, func() {
		pool.mu.Lock()
		delete(pool.givenOut, wr)
		pool.setSharedRates()
		pool.mu.Unlock()
	}
}
func (pool *WriterPool) Get(w io.Writer) (writer io.Writer, release func()) {
	// don't export a ThrottlerWriter to prevent users changing the rate
	// and expecting their change to be respected, since we might modify
	// the rate under their feet

	// make the initial rate be 0, the actual rate is
	// set in the call to `setSharedRates`.
	wr := ThrottledWriter(w, 0, pool.maxBurst)

	pool.mu.Lock()
	pool.givenOut[wr] = struct{}{}
	pool.setSharedRates()
	pool.mu.Unlock()

	return wr, func() {
		pool.mu.Lock()
		delete(pool.givenOut, wr)
		pool.setSharedRates()
		pool.mu.Unlock()
	}
}
func ( pool * WriterPool ) Get ( w io . Writer ) ( writer io . Writer , release func ( ) ) { // don't export a ThrottlerWriter to prevent users changing the rate // and expecting their change to be respected, since we might modify // the rate under their feet // make the initial rate be 0, the actual rate is // set in the call to `setSharedRates`. wr := ThrottledWriter ( w , 0 , pool . maxBurst ) pool . mu . Lock ( ) pool . givenOut [ wr ] = struct { } { } pool . setSharedRates ( ) pool . mu . Unlock ( ) return wr , func ( ) { pool . mu . Lock ( ) delete ( pool . givenOut , wr ) pool . setSharedRates ( ) pool . mu . Unlock ( ) } }
// Get a throttled writer that wraps w.
Get a throttled writer that wraps w .