Merge pull request #70764 from wenjiaswe/automated-cherry-pick-of-#70663-upstream-release-1.12

Automated cherry pick of #70663: update  godeps for golang.org/x/net/... to

Kubernetes-commit: 6370ab3b63cbeed89bbe38aa7a757005eea9f22d
This commit is contained in:
Kubernetes Publisher
2018-11-28 07:50:36 -08:00
31 changed files with 6346 additions and 5730 deletions
+19 -2
View File
@@ -17,6 +17,7 @@ limitations under the License.
package workqueue
import (
"context"
"sync"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
@@ -24,9 +25,20 @@ import (
type DoWorkPieceFunc func(piece int)
// Parallelize is a very simple framework that allow for parallelizing
// Parallelize is a very simple framework that allows for parallelizing
// N independent pieces of work.
func Parallelize(workers, pieces int, doWorkPiece DoWorkPieceFunc) {
ParallelizeUntil(nil, workers, pieces, doWorkPiece)
}
// ParallelizeUntil is a framework that allows for parallelizing N
// independent pieces of work until done or the context is canceled.
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
@@ -44,7 +56,12 @@ func Parallelize(workers, pieces int, doWorkPiece DoWorkPieceFunc) {
defer utilruntime.HandleCrash()
defer wg.Done()
for piece := range toProcess {
doWorkPiece(piece)
select {
case <-stop:
return
default:
doWorkPiece(piece)
}
}
}()
}