Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Unified Diff: common/parallel/workPool.go

Issue 1610993002: LogDog: Add collector service implementation. (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: common/parallel/workPool.go
diff --git a/common/parallel/workPool.go b/common/parallel/workPool.go
index 0e749eb07e108445b0cc357afbdeea328536673b..e27f5b828d7bf8e3ee6bee35540b4e08b74b953d 100644
--- a/common/parallel/workPool.go
+++ b/common/parallel/workPool.go
@@ -23,8 +23,17 @@ func WorkPool(workers int, gen func(chan<- func() error)) error {
}
sem := make(Semaphore, workers)
- errchan := make(chan error, workers)
- funchan := make(chan func() error, workers)
+ return Run(sem, gen)
+}
+
+// Run executes task functions produced by a generator method. Execution is
+// throttled by an optional Semaphore, requiring a token prior to dispatch.
+//
+// Run blocks until all the generator completes and all workers have finished
+// their tasks, returning a MultiError if a failure was encountered.
+func Run(sem Semaphore, gen func(chan<- func() error)) error {
dnj (Google) 2016/01/21 04:36:24 Useful b/c the FanOutIn model is great, but someti
+ errchan := make(chan error, cap(sem))
+ funchan := make(chan func() error, cap(sem))
go func() {
defer close(funchan)

Powered by Google App Engine
This is Rietveld 408576698