code: func (ref *AsyncProducer) Close(async ...bool) error {
  	var err error
  	defer func() {
  		if ref.closed {
  			ref.Unlock()
  			return
  		}
  		ref.closed = true
  		close(ref.closeChannel)
  
  		// decrement external wait group
  		if ref.xwg != nil {
  			ref.xwg.Done()
  		}
  		ref.Unlock()
  	}()
  
  	ref.Lock()
  	if ref.closed {
  		return nil
  	}
  
  	if async != nil && len(async) > 0 {
  		ref.Debug("async close")
  		ref.Producer.AsyncClose()
  	} else {
  		ref.Debug("sync close")
  		ref.Producer.Close()
  	}
  	if err != nil {
  		ref.Errorf("asyncProducer close error: %v", err)
  		return err
  	}
  	if ref.Client != nil && !ref.Client.Closed() {
  		err = ref.Client.Close()
  		if err != nil {
  			ref.Errorf("client close error: %v", err)
  			return err
  		}
  	}
  
  	return nil
  }
docs: // Close closes the client and producer