code: func runImpl(gen func(chan<- func() error), workC chan<- WorkItem, then func()) <-chan error {
  	errC := make(chan error)
  	taskC := make(chan func() error)
  
  	// Execute our generator method.
  	go func() {
  		defer close(taskC)
  		gen(taskC)
  	}()
  
  	// Read tasks from taskC and dispatch actual work.
  	go func() {
  		if then != nil {
  			defer then()
  		}
  
  		// Use a counter to track the number of active jobs.
  		//
  		// Add one implicit job for the outer task loop. This will ensure that if
  		// we will never hit 0 until all of our tasks have dispatched.
  		count := int32(1)
  		finish := func() {
  			if atomic.AddInt32(&count, -1) == 0 {
  				close(errC)
  			}
  		}
  		defer finish()
  
  		// Dispatch the tasks in the task channel.
  		for task := range taskC {
  			atomic.AddInt32(&count, 1)
  			workC <- WorkItem{
  				F:     task,
  				ErrC:  errC,
  				After: finish,
  			}
  		}
  	}()
  
  	return errC
  }
docs: // runImpl sets up a localized system where a generator generates tasks and
  // dispatches them to the supplied work channel.
  //
  // After all tasks have been written to the work channel, then is called.