From cc8b8cf7a44b706e0e2ae85ad93b4b3fa864c7e0 Mon Sep 17 00:00:00 2001 From: Mark McGranaghan Date: Wed, 19 Sep 2012 23:35:34 -0700 Subject: [PATCH] worker pool --- README | 1 - src/xx-worker-pool.go | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/xx-worker-pool.go diff --git a/README b/README index 3d1d070..31395a7 100644 --- a/README +++ b/README @@ -42,7 +42,6 @@ gobyexample.com signups * web app * serve static files * mongo -* worker pool * rate limiting * time formatting * typed json parse/unparse diff --git a/src/xx-worker-pool.go b/src/xx-worker-pool.go new file mode 100644 index 0000000..e7c5e91 --- /dev/null +++ b/src/xx-worker-pool.go @@ -0,0 +1,27 @@ +package main + +import ("fmt"; "time") + +func main() { + jobs := make(chan int, 100) + acks := make(chan bool, 100) + + for w := 0; w < 10; w++ { + go func() { + for j := range jobs { + fmt.Println("worker", w, "processing job", j) + time.Sleep(time.Millisecond * 150) + acks <- true + } + }() + } + + for j := 0; j < 100; j++ { + jobs <- j + } + + for a := 0; a < 100; a++ { + <- acks + } + fmt.Println("all done") +}