code: func (r *remoteSubsystem) Wait() error {
  	var lastErr error
  
  	for i := 0; i < 3; i++ {
  		select {
  		case err := <-r.errorCh:
  			if err != nil && err != io.EOF {
  				r.log.Warnf("Connection problem: %v %T", trace.DebugReport(err), err)
  				lastErr = err
  			}
  		case <-r.ctx.Done():
  			lastErr = trace.ConnectionProblem(nil, "context is closing")
  		}
  	}
  
  	// emit an event to the audit log with the result of execution
  	r.emitAuditEvent(lastErr)
  
  	return lastErr
  }
docs: // Wait until the remote subsystem has finished execution and then return the last error.