initial commit
This commit is contained in:
commit
493ce92e02
62 changed files with 1213 additions and 0 deletions
BIN
channel-buffering/chanbuffer
Executable file
BIN
channel-buffering/chanbuffer
Executable file
Binary file not shown.
27
channel-buffering/chanbuffer.go
Normal file
27
channel-buffering/chanbuffer.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main(){
|
||||
|
||||
//by default channels are unbuffered,
|
||||
//meaning that they will only accept
|
||||
//sends(chan <-) if there is a corresponding receive (<- chan) ready
|
||||
//to receive the sent value. Buffered Channels accept a limited
|
||||
//number of values without a corresponding receiver for those values
|
||||
|
||||
|
||||
//here we make a channel of strings buffering up to 2 values
|
||||
messages := make(chan string, 2)
|
||||
|
||||
//because this channel is buffered,
|
||||
//we can send these values into the channel without a
|
||||
//corresponding concurrent receive
|
||||
messages <- "buffered"
|
||||
messages <- "channel"
|
||||
|
||||
|
||||
//later we can receive these two values as usual
|
||||
fmt.Println(<-messages)
|
||||
fmt.Println(<-messages)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue