From 1f30b700bd0c267d7f967750732ad442447996a4 Mon Sep 17 00:00:00 2001 From: Mark McGranaghan Date: Sun, 30 Sep 2012 20:24:50 -0700 Subject: [PATCH] closing channels --- src/039-closing-channels/closing-channels.go | 33 +++++++++++++++++++ src/{039-timers => 040-timers}/timers.go | 0 src/{039-timers => 040-timers}/tiners.sh | 0 src/{040-tickers => 041-tickers}/tickers.go | 0 src/{040-tickers => 041-tickers}/tickers.sh | 0 .../state-goroutine.go | 0 src/{042-sorting => 043-sorting}/sorting.go | 0 src/{042-sorting => 043-sorting}/sorting.sh | 0 .../sorting-by-functions.go | 0 .../sorting-by-functions.sh | 0 .../collection-functions.go | 0 .../string-functions.go | 0 .../string-formatting.go | 0 .../string-formatting.sh | 0 src/{047-regexs => 048-regexs}/regexs.go | 0 src/{047-regexs => 048-regexs}/regexs.sh | 0 src/{048-bytes => 049-bytes}/bytes.go | 0 src/{049-json => 050-json}/json.go | 0 src/{050-time => 051-time}/time.go | 0 src/{050-time => 051-time}/time.sh | 0 src/{051-epochs => 052-epochs}/epochs.go | 0 src/{051-epochs => 052-epochs}/epochs.sh | 0 .../elapsed-time.go | 0 .../random-numbers.go | 0 .../random-numbers.sh | 0 .../number-parsing.go | 0 .../number-parsing.sh | 0 src/{055-urls => 056-urls}/urls.go | 0 src/{055-urls => 056-urls}/urls.sh | 0 .../sha1-hashes.go | 0 .../sha1-hashes.sh | 0 .../base64-encoding.go | 0 .../reading-files.go | 0 .../writing-files.go | 0 .../line-filters.go | 0 .../line-filters.sh | 0 .../command-line-arguments.go | 0 .../command-line-arguments.sh | 0 .../command-line-flags.go | 0 .../environment-variables.go | 0 .../environment-variables.sh | 0 .../spawning-processes.go | 0 .../spawning-processes.sh | 0 .../execing-processes.go | 0 src/{066-signals => 067-signals}/signals.go | 0 src/{066-signals => 067-signals}/signals.sh | 0 src/{067-exit => 068-exit}/exit.go | 0 src/{067-exit => 068-exit}/exit.sh | 0 .../http-client.go | 0 .../https-client.go | 0 src/{070-redis => 071-redis}/redis.go | 0 src/{070-redis => 071-redis}/redis.sh | 0 .../postgres.go | 0 .../postgres.sh | 0 .../sending-email.go | 0 .../hello-web.go | 0 .../responses.go | 0 .../responses.sh | 0 .../request-routing.go | 0 .../request-routing.sh | 0 .../request-logging.go | 0 .../static-content.go | 0 .../static-content.sh | 0 .../basic-authentication.go | 0 .../canonical-hosts.go | 0 .../canonical-hosts.sh | 0 .../middleware.go | 0 .../graceful-shutdown.go | 0 .../graceful-shutdown.sh | 0 .../https-servers.go | 0 .../https-servers.sh | 0 tool/index.txt | 2 +- 72 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/039-closing-channels/closing-channels.go rename src/{039-timers => 040-timers}/timers.go (100%) rename src/{039-timers => 040-timers}/tiners.sh (100%) rename src/{040-tickers => 041-tickers}/tickers.go (100%) rename src/{040-tickers => 041-tickers}/tickers.sh (100%) rename src/{041-state-goroutine => 042-state-goroutine}/state-goroutine.go (100%) rename src/{042-sorting => 043-sorting}/sorting.go (100%) rename src/{042-sorting => 043-sorting}/sorting.sh (100%) rename src/{043-sorting-by-functions => 044-sorting-by-functions}/sorting-by-functions.go (100%) rename src/{043-sorting-by-functions => 044-sorting-by-functions}/sorting-by-functions.sh (100%) rename src/{044-collection-functions => 045-collection-functions}/collection-functions.go (100%) rename src/{045-string-functions => 046-string-functions}/string-functions.go (100%) rename src/{046-string-formatting => 047-string-formatting}/string-formatting.go (100%) rename src/{046-string-formatting => 047-string-formatting}/string-formatting.sh (100%) rename src/{047-regexs => 048-regexs}/regexs.go (100%) rename src/{047-regexs => 048-regexs}/regexs.sh (100%) rename src/{048-bytes => 049-bytes}/bytes.go (100%) rename src/{049-json => 050-json}/json.go (100%) rename src/{050-time => 051-time}/time.go (100%) rename src/{050-time => 051-time}/time.sh (100%) rename src/{051-epochs => 052-epochs}/epochs.go (100%) rename src/{051-epochs => 052-epochs}/epochs.sh (100%) rename src/{052-elapsed-time => 053-elapsed-time}/elapsed-time.go (100%) rename src/{053-random-numbers => 054-random-numbers}/random-numbers.go (100%) rename src/{053-random-numbers => 054-random-numbers}/random-numbers.sh (100%) rename src/{054-number-parsing => 055-number-parsing}/number-parsing.go (100%) rename src/{054-number-parsing => 055-number-parsing}/number-parsing.sh (100%) rename src/{055-urls => 056-urls}/urls.go (100%) rename src/{055-urls => 056-urls}/urls.sh (100%) rename src/{056-sha1-hashes => 057-sha1-hashes}/sha1-hashes.go (100%) rename src/{056-sha1-hashes => 057-sha1-hashes}/sha1-hashes.sh (100%) rename src/{057-base64-encoding => 058-base64-encoding}/base64-encoding.go (100%) rename src/{058-reading-files => 059-reading-files}/reading-files.go (100%) rename src/{059-writing-files => 060-writing-files}/writing-files.go (100%) rename src/{060-line-filters => 061-line-filters}/line-filters.go (100%) rename src/{060-line-filters => 061-line-filters}/line-filters.sh (100%) rename src/{061-command-line-arguments => 062-command-line-arguments}/command-line-arguments.go (100%) rename src/{061-command-line-arguments => 062-command-line-arguments}/command-line-arguments.sh (100%) rename src/{062-command-line-flags => 063-command-line-flags}/command-line-flags.go (100%) rename src/{063-environment-variables => 064-environment-variables}/environment-variables.go (100%) rename src/{063-environment-variables => 064-environment-variables}/environment-variables.sh (100%) rename src/{064-spawning-processes => 065-spawning-processes}/spawning-processes.go (100%) rename src/{064-spawning-processes => 065-spawning-processes}/spawning-processes.sh (100%) rename src/{065-execing-processes => 066-execing-processes}/execing-processes.go (100%) rename src/{066-signals => 067-signals}/signals.go (100%) rename src/{066-signals => 067-signals}/signals.sh (100%) rename src/{067-exit => 068-exit}/exit.go (100%) rename src/{067-exit => 068-exit}/exit.sh (100%) rename src/{068-http-client => 069-http-client}/http-client.go (100%) rename src/{069-https-client => 070-https-client}/https-client.go (100%) rename src/{070-redis => 071-redis}/redis.go (100%) rename src/{070-redis => 071-redis}/redis.sh (100%) rename src/{071-postgres => 072-postgres}/postgres.go (100%) rename src/{071-postgres => 072-postgres}/postgres.sh (100%) rename src/{072-sending-email => 073-sending-email}/sending-email.go (100%) rename src/{073-hello-web => 074-hello-web}/hello-web.go (100%) rename src/{074-responses => 075-responses}/responses.go (100%) rename src/{074-responses => 075-responses}/responses.sh (100%) rename src/{075-request-routing => 076-request-routing}/request-routing.go (100%) rename src/{075-request-routing => 076-request-routing}/request-routing.sh (100%) rename src/{076-request-logging => 077-request-logging}/request-logging.go (100%) rename src/{077-static-content => 078-static-content}/static-content.go (100%) rename src/{077-static-content => 078-static-content}/static-content.sh (100%) rename src/{078-basic-authentication => 079-basic-authentication}/basic-authentication.go (100%) rename src/{079-canonical-hosts => 080-canonical-hosts}/canonical-hosts.go (100%) rename src/{079-canonical-hosts => 080-canonical-hosts}/canonical-hosts.sh (100%) rename src/{080-middleware => 081-middleware}/middleware.go (100%) rename src/{081-graceful-shutdown => 082-graceful-shutdown}/graceful-shutdown.go (100%) rename src/{081-graceful-shutdown => 082-graceful-shutdown}/graceful-shutdown.sh (100%) rename src/{082-https-servers => 083-https-servers}/https-servers.go (100%) rename src/{082-https-servers => 083-https-servers}/https-servers.sh (100%) diff --git a/src/039-closing-channels/closing-channels.go b/src/039-closing-channels/closing-channels.go new file mode 100644 index 0000000..7cd7e89 --- /dev/null +++ b/src/039-closing-channels/closing-channels.go @@ -0,0 +1,33 @@ +package main + +import "fmt" +import "time" + +func main() { + jobs := make(chan bool, 5) + done := make(chan bool) + + go func() { + for { + _, more := <- jobs + if more { + fmt.Println("received job") + } else { + fmt.Println("received all") + done <- true + return + } + } + }() + + for i := 0; i < 5 ; i++ { + jobs <- false + fmt.Println("sent job") + } + + time.Sleep(100 * time.Millisecond) + close(jobs) + fmt.Println("sent all") + + <- done +} diff --git a/src/039-timers/timers.go b/src/040-timers/timers.go similarity index 100% rename from src/039-timers/timers.go rename to src/040-timers/timers.go diff --git a/src/039-timers/tiners.sh b/src/040-timers/tiners.sh similarity index 100% rename from src/039-timers/tiners.sh rename to src/040-timers/tiners.sh diff --git a/src/040-tickers/tickers.go b/src/041-tickers/tickers.go similarity index 100% rename from src/040-tickers/tickers.go rename to src/041-tickers/tickers.go diff --git a/src/040-tickers/tickers.sh b/src/041-tickers/tickers.sh similarity index 100% rename from src/040-tickers/tickers.sh rename to src/041-tickers/tickers.sh diff --git a/src/041-state-goroutine/state-goroutine.go b/src/042-state-goroutine/state-goroutine.go similarity index 100% rename from src/041-state-goroutine/state-goroutine.go rename to src/042-state-goroutine/state-goroutine.go diff --git a/src/042-sorting/sorting.go b/src/043-sorting/sorting.go similarity index 100% rename from src/042-sorting/sorting.go rename to src/043-sorting/sorting.go diff --git a/src/042-sorting/sorting.sh b/src/043-sorting/sorting.sh similarity index 100% rename from src/042-sorting/sorting.sh rename to src/043-sorting/sorting.sh diff --git a/src/043-sorting-by-functions/sorting-by-functions.go b/src/044-sorting-by-functions/sorting-by-functions.go similarity index 100% rename from src/043-sorting-by-functions/sorting-by-functions.go rename to src/044-sorting-by-functions/sorting-by-functions.go diff --git a/src/043-sorting-by-functions/sorting-by-functions.sh b/src/044-sorting-by-functions/sorting-by-functions.sh similarity index 100% rename from src/043-sorting-by-functions/sorting-by-functions.sh rename to src/044-sorting-by-functions/sorting-by-functions.sh diff --git a/src/044-collection-functions/collection-functions.go b/src/045-collection-functions/collection-functions.go similarity index 100% rename from src/044-collection-functions/collection-functions.go rename to src/045-collection-functions/collection-functions.go diff --git a/src/045-string-functions/string-functions.go b/src/046-string-functions/string-functions.go similarity index 100% rename from src/045-string-functions/string-functions.go rename to src/046-string-functions/string-functions.go diff --git a/src/046-string-formatting/string-formatting.go b/src/047-string-formatting/string-formatting.go similarity index 100% rename from src/046-string-formatting/string-formatting.go rename to src/047-string-formatting/string-formatting.go diff --git a/src/046-string-formatting/string-formatting.sh b/src/047-string-formatting/string-formatting.sh similarity index 100% rename from src/046-string-formatting/string-formatting.sh rename to src/047-string-formatting/string-formatting.sh diff --git a/src/047-regexs/regexs.go b/src/048-regexs/regexs.go similarity index 100% rename from src/047-regexs/regexs.go rename to src/048-regexs/regexs.go diff --git a/src/047-regexs/regexs.sh b/src/048-regexs/regexs.sh similarity index 100% rename from src/047-regexs/regexs.sh rename to src/048-regexs/regexs.sh diff --git a/src/048-bytes/bytes.go b/src/049-bytes/bytes.go similarity index 100% rename from src/048-bytes/bytes.go rename to src/049-bytes/bytes.go diff --git a/src/049-json/json.go b/src/050-json/json.go similarity index 100% rename from src/049-json/json.go rename to src/050-json/json.go diff --git a/src/050-time/time.go b/src/051-time/time.go similarity index 100% rename from src/050-time/time.go rename to src/051-time/time.go diff --git a/src/050-time/time.sh b/src/051-time/time.sh similarity index 100% rename from src/050-time/time.sh rename to src/051-time/time.sh diff --git a/src/051-epochs/epochs.go b/src/052-epochs/epochs.go similarity index 100% rename from src/051-epochs/epochs.go rename to src/052-epochs/epochs.go diff --git a/src/051-epochs/epochs.sh b/src/052-epochs/epochs.sh similarity index 100% rename from src/051-epochs/epochs.sh rename to src/052-epochs/epochs.sh diff --git a/src/052-elapsed-time/elapsed-time.go b/src/053-elapsed-time/elapsed-time.go similarity index 100% rename from src/052-elapsed-time/elapsed-time.go rename to src/053-elapsed-time/elapsed-time.go diff --git a/src/053-random-numbers/random-numbers.go b/src/054-random-numbers/random-numbers.go similarity index 100% rename from src/053-random-numbers/random-numbers.go rename to src/054-random-numbers/random-numbers.go diff --git a/src/053-random-numbers/random-numbers.sh b/src/054-random-numbers/random-numbers.sh similarity index 100% rename from src/053-random-numbers/random-numbers.sh rename to src/054-random-numbers/random-numbers.sh diff --git a/src/054-number-parsing/number-parsing.go b/src/055-number-parsing/number-parsing.go similarity index 100% rename from src/054-number-parsing/number-parsing.go rename to src/055-number-parsing/number-parsing.go diff --git a/src/054-number-parsing/number-parsing.sh b/src/055-number-parsing/number-parsing.sh similarity index 100% rename from src/054-number-parsing/number-parsing.sh rename to src/055-number-parsing/number-parsing.sh diff --git a/src/055-urls/urls.go b/src/056-urls/urls.go similarity index 100% rename from src/055-urls/urls.go rename to src/056-urls/urls.go diff --git a/src/055-urls/urls.sh b/src/056-urls/urls.sh similarity index 100% rename from src/055-urls/urls.sh rename to src/056-urls/urls.sh diff --git a/src/056-sha1-hashes/sha1-hashes.go b/src/057-sha1-hashes/sha1-hashes.go similarity index 100% rename from src/056-sha1-hashes/sha1-hashes.go rename to src/057-sha1-hashes/sha1-hashes.go diff --git a/src/056-sha1-hashes/sha1-hashes.sh b/src/057-sha1-hashes/sha1-hashes.sh similarity index 100% rename from src/056-sha1-hashes/sha1-hashes.sh rename to src/057-sha1-hashes/sha1-hashes.sh diff --git a/src/057-base64-encoding/base64-encoding.go b/src/058-base64-encoding/base64-encoding.go similarity index 100% rename from src/057-base64-encoding/base64-encoding.go rename to src/058-base64-encoding/base64-encoding.go diff --git a/src/058-reading-files/reading-files.go b/src/059-reading-files/reading-files.go similarity index 100% rename from src/058-reading-files/reading-files.go rename to src/059-reading-files/reading-files.go diff --git a/src/059-writing-files/writing-files.go b/src/060-writing-files/writing-files.go similarity index 100% rename from src/059-writing-files/writing-files.go rename to src/060-writing-files/writing-files.go diff --git a/src/060-line-filters/line-filters.go b/src/061-line-filters/line-filters.go similarity index 100% rename from src/060-line-filters/line-filters.go rename to src/061-line-filters/line-filters.go diff --git a/src/060-line-filters/line-filters.sh b/src/061-line-filters/line-filters.sh similarity index 100% rename from src/060-line-filters/line-filters.sh rename to src/061-line-filters/line-filters.sh diff --git a/src/061-command-line-arguments/command-line-arguments.go b/src/062-command-line-arguments/command-line-arguments.go similarity index 100% rename from src/061-command-line-arguments/command-line-arguments.go rename to src/062-command-line-arguments/command-line-arguments.go diff --git a/src/061-command-line-arguments/command-line-arguments.sh b/src/062-command-line-arguments/command-line-arguments.sh similarity index 100% rename from src/061-command-line-arguments/command-line-arguments.sh rename to src/062-command-line-arguments/command-line-arguments.sh diff --git a/src/062-command-line-flags/command-line-flags.go b/src/063-command-line-flags/command-line-flags.go similarity index 100% rename from src/062-command-line-flags/command-line-flags.go rename to src/063-command-line-flags/command-line-flags.go diff --git a/src/063-environment-variables/environment-variables.go b/src/064-environment-variables/environment-variables.go similarity index 100% rename from src/063-environment-variables/environment-variables.go rename to src/064-environment-variables/environment-variables.go diff --git a/src/063-environment-variables/environment-variables.sh b/src/064-environment-variables/environment-variables.sh similarity index 100% rename from src/063-environment-variables/environment-variables.sh rename to src/064-environment-variables/environment-variables.sh diff --git a/src/064-spawning-processes/spawning-processes.go b/src/065-spawning-processes/spawning-processes.go similarity index 100% rename from src/064-spawning-processes/spawning-processes.go rename to src/065-spawning-processes/spawning-processes.go diff --git a/src/064-spawning-processes/spawning-processes.sh b/src/065-spawning-processes/spawning-processes.sh similarity index 100% rename from src/064-spawning-processes/spawning-processes.sh rename to src/065-spawning-processes/spawning-processes.sh diff --git a/src/065-execing-processes/execing-processes.go b/src/066-execing-processes/execing-processes.go similarity index 100% rename from src/065-execing-processes/execing-processes.go rename to src/066-execing-processes/execing-processes.go diff --git a/src/066-signals/signals.go b/src/067-signals/signals.go similarity index 100% rename from src/066-signals/signals.go rename to src/067-signals/signals.go diff --git a/src/066-signals/signals.sh b/src/067-signals/signals.sh similarity index 100% rename from src/066-signals/signals.sh rename to src/067-signals/signals.sh diff --git a/src/067-exit/exit.go b/src/068-exit/exit.go similarity index 100% rename from src/067-exit/exit.go rename to src/068-exit/exit.go diff --git a/src/067-exit/exit.sh b/src/068-exit/exit.sh similarity index 100% rename from src/067-exit/exit.sh rename to src/068-exit/exit.sh diff --git a/src/068-http-client/http-client.go b/src/069-http-client/http-client.go similarity index 100% rename from src/068-http-client/http-client.go rename to src/069-http-client/http-client.go diff --git a/src/069-https-client/https-client.go b/src/070-https-client/https-client.go similarity index 100% rename from src/069-https-client/https-client.go rename to src/070-https-client/https-client.go diff --git a/src/070-redis/redis.go b/src/071-redis/redis.go similarity index 100% rename from src/070-redis/redis.go rename to src/071-redis/redis.go diff --git a/src/070-redis/redis.sh b/src/071-redis/redis.sh similarity index 100% rename from src/070-redis/redis.sh rename to src/071-redis/redis.sh diff --git a/src/071-postgres/postgres.go b/src/072-postgres/postgres.go similarity index 100% rename from src/071-postgres/postgres.go rename to src/072-postgres/postgres.go diff --git a/src/071-postgres/postgres.sh b/src/072-postgres/postgres.sh similarity index 100% rename from src/071-postgres/postgres.sh rename to src/072-postgres/postgres.sh diff --git a/src/072-sending-email/sending-email.go b/src/073-sending-email/sending-email.go similarity index 100% rename from src/072-sending-email/sending-email.go rename to src/073-sending-email/sending-email.go diff --git a/src/073-hello-web/hello-web.go b/src/074-hello-web/hello-web.go similarity index 100% rename from src/073-hello-web/hello-web.go rename to src/074-hello-web/hello-web.go diff --git a/src/074-responses/responses.go b/src/075-responses/responses.go similarity index 100% rename from src/074-responses/responses.go rename to src/075-responses/responses.go diff --git a/src/074-responses/responses.sh b/src/075-responses/responses.sh similarity index 100% rename from src/074-responses/responses.sh rename to src/075-responses/responses.sh diff --git a/src/075-request-routing/request-routing.go b/src/076-request-routing/request-routing.go similarity index 100% rename from src/075-request-routing/request-routing.go rename to src/076-request-routing/request-routing.go diff --git a/src/075-request-routing/request-routing.sh b/src/076-request-routing/request-routing.sh similarity index 100% rename from src/075-request-routing/request-routing.sh rename to src/076-request-routing/request-routing.sh diff --git a/src/076-request-logging/request-logging.go b/src/077-request-logging/request-logging.go similarity index 100% rename from src/076-request-logging/request-logging.go rename to src/077-request-logging/request-logging.go diff --git a/src/077-static-content/static-content.go b/src/078-static-content/static-content.go similarity index 100% rename from src/077-static-content/static-content.go rename to src/078-static-content/static-content.go diff --git a/src/077-static-content/static-content.sh b/src/078-static-content/static-content.sh similarity index 100% rename from src/077-static-content/static-content.sh rename to src/078-static-content/static-content.sh diff --git a/src/078-basic-authentication/basic-authentication.go b/src/079-basic-authentication/basic-authentication.go similarity index 100% rename from src/078-basic-authentication/basic-authentication.go rename to src/079-basic-authentication/basic-authentication.go diff --git a/src/079-canonical-hosts/canonical-hosts.go b/src/080-canonical-hosts/canonical-hosts.go similarity index 100% rename from src/079-canonical-hosts/canonical-hosts.go rename to src/080-canonical-hosts/canonical-hosts.go diff --git a/src/079-canonical-hosts/canonical-hosts.sh b/src/080-canonical-hosts/canonical-hosts.sh similarity index 100% rename from src/079-canonical-hosts/canonical-hosts.sh rename to src/080-canonical-hosts/canonical-hosts.sh diff --git a/src/080-middleware/middleware.go b/src/081-middleware/middleware.go similarity index 100% rename from src/080-middleware/middleware.go rename to src/081-middleware/middleware.go diff --git a/src/081-graceful-shutdown/graceful-shutdown.go b/src/082-graceful-shutdown/graceful-shutdown.go similarity index 100% rename from src/081-graceful-shutdown/graceful-shutdown.go rename to src/082-graceful-shutdown/graceful-shutdown.go diff --git a/src/081-graceful-shutdown/graceful-shutdown.sh b/src/082-graceful-shutdown/graceful-shutdown.sh similarity index 100% rename from src/081-graceful-shutdown/graceful-shutdown.sh rename to src/082-graceful-shutdown/graceful-shutdown.sh diff --git a/src/082-https-servers/https-servers.go b/src/083-https-servers/https-servers.go similarity index 100% rename from src/082-https-servers/https-servers.go rename to src/083-https-servers/https-servers.go diff --git a/src/082-https-servers/https-servers.sh b/src/083-https-servers/https-servers.sh similarity index 100% rename from src/082-https-servers/https-servers.sh rename to src/083-https-servers/https-servers.sh diff --git a/tool/index.txt b/tool/index.txt index 7b54988..c1cffd5 100644 --- a/tool/index.txt +++ b/tool/index.txt @@ -44,7 +44,7 @@ scatter-gather rate-limiting worker-pools nonblocking-channel-operations ~ -closing-channels ~ +closing-channels timers tickers state-goroutine