code: func (t *transfer) Watch(progressOutput progress.Output) *Watcher {
  	t.mu.Lock()
  	defer t.mu.Unlock()
  
  	w := &Watcher{
  		releaseChan: make(chan struct{}),
  		signalChan:  make(chan struct{}),
  		running:     make(chan struct{}),
  	}
  
  	t.watchers[w.releaseChan] = w
  
  	if t.broadcastDone {
  		close(w.running)
  		return w
  	}
  
  	go func() {
  		defer func() {
  			close(w.running)
  		}()
  		var (
  			done           bool
  			lastWritten    progress.Progress
  			hasLastWritten bool
  		)
  		for {
  			t.mu.Lock()
  			hasLastProgress := t.hasLastProgress
  			lastProgress := t.lastProgress
  			t.mu.Unlock()
  
  			// Make sure we don't write the last progress item
  			// twice.
  			if hasLastProgress && (!done || !hasLastWritten || lastProgress != lastWritten) {
  				progressOutput.WriteProgress(lastProgress)
  				lastWritten = lastProgress
  				hasLastWritten = true
  			}
  
  			if done {
  				return
  			}
  
  			select {
  			case <-w.signalChan:
  			case <-w.releaseChan:
  				done = true
  				// Since the watcher is going to detach, make
  				// sure the broadcaster is caught up so we
  				// don't miss anything.
  				select {
  				case t.broadcastSyncChan <- struct{}{}:
  				case <-t.running:
  				}
  			case <-t.running:
  				done = true
  			}
  		}
  	}()
  
  	return w
  }
docs: // Watch adds a watcher to the transfer. The supplied channel gets progress
  // updates and is closed when the transfer finishes.