github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/talks/2014/go4java/runner/embed.go (about)

     1  package runner
     2  
     3  // RunCounter2 is completely equivalent to RunCounter,
     4  // but uses struct embedding to avoid the boilerplate of redeclaring
     5  // the Name method.
     6  type RunCounter2 struct {
     7  	Runner // HL
     8  	count  int
     9  }
    10  
    11  func NewRunCounter2(name string) *RunCounter2 {
    12  	return &RunCounter2{Runner{name}, 0}
    13  }
    14  
    15  func (r *RunCounter2) Run(t Task) {
    16  	r.count++
    17  	r.Runner.Run(t) // HL
    18  }
    19  
    20  func (r *RunCounter2) RunAll(ts []Task) {
    21  	r.count += len(ts)
    22  	r.Runner.RunAll(ts) // HL
    23  }
    24  
    25  func (r *RunCounter2) Count() int { return r.count }