code: func ParallelizeUntil(ctx context.Context, workers, pieces int, doWorkPiece DoWorkPieceFunc) {
  	var stop <-chan struct{}
  	if ctx != nil {
  		stop = ctx.Done()
  	}
  
  	toProcess := make(chan int, pieces)
  	for i := 0; i < pieces; i++ {
  		toProcess <- i
  	}
  	close(toProcess)
  
  	if pieces < workers {
  		workers = pieces
  	}
  
  	wg := sync.WaitGroup{}
  	wg.Add(workers)
  	for i := 0; i < workers; i++ {
  		go func() {
  			defer utilruntime.HandleCrash()
  			defer wg.Done()
  			for piece := range toProcess {
  				select {
  				case <-stop:
  					return
  				default:
  					doWorkPiece(piece)
  				}
  			}
  		}()
  	}
  	wg.Wait()
  }
docs: // ParallelizeUntil is a framework that allows for parallelizing N
  // independent pieces of work until done or the context is canceled.