FAQ
Also, in this particular example, sending a message to an unbuffered
channel would have been just fine. But in some cases, using a buffer (or
closing the channel instead of sending) to make communication asynchronous
can avoid deadlocks.

On Wednesday, July 29, 2015 at 4:14:21 PM UTC+2, Yesudeep Mangalapilly
wrote:
Namaste,

I'm new to concurrency and Go, so my question may be a bit naive.
While reading through this example here:

http://play.golang.org/p/0DfW-1RMqi

--- code ---
package main

import "fmt"
import "time"

func worker(done chan bool) {
time.Sleep(time.Second)
done <- true
}

func main() {
done := make(chan bool, 1) // What is the significance of using 1
as capacity here?
go worker(done)
<-done
}
--- end code ---

Why use 1 to create a buffered channel? Can we not signal "done" using a
regular non-buffered
channel?

Cheers,
Yesudeep.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 4 of 7 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJul 29, '15 at 2:14p
activeJul 29, '15 at 9:12p
posts7
users5
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase