code: func (nc *Conn) Barrier(f func()) error {
  	nc.mu.Lock()
  	if nc.isClosed() {
  		nc.mu.Unlock()
  		return ErrConnectionClosed
  	}
  	nc.subsMu.Lock()
  	// Need to figure out how many non chan subscriptions there are
  	numSubs := 0
  	for _, sub := range nc.subs {
  		if sub.typ == AsyncSubscription {
  			numSubs++
  		}
  	}
  	if numSubs == 0 {
  		nc.subsMu.Unlock()
  		nc.mu.Unlock()
  		f()
  		return nil
  	}
  	barrier := &barrierInfo{refs: int64(numSubs), f: f}
  	for _, sub := range nc.subs {
  		sub.mu.Lock()
  		if sub.mch == nil {
  			msg := &Msg{barrier: barrier}
  			// Push onto the async pList
  			if sub.pTail != nil {
  				sub.pTail.next = msg
  			} else {
  				sub.pHead = msg
  				sub.pCond.Signal()
  			}
  			sub.pTail = msg
  		}
  		sub.mu.Unlock()
  	}
  	nc.subsMu.Unlock()
  	nc.mu.Unlock()
  	return nil
  }
docs: // Barrier schedules the given function `f` to all registered asynchronous
  // subscriptions.
  // Only the last subscription to see this barrier will invoke the function.
  // If no subscription is registered at the time of this call, `f()` is invoked
  // right away.
  // ErrConnectionClosed is returned if the connection is closed prior to
  // the call.