Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e87f108

Browse files
author
libo-ps
committed
channels
1 parent c27738d commit e87f108

2 files changed

Lines changed: 35 additions & 37 deletions

File tree

go/src/channels.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package main
2+
3+
/*
4+
- concept:
5+
Channels are the pipes that connect concurrent goroutines. You can send values into channels from one goroutine and receive those values into another goroutine.
6+
7+
- uage:
8+
create a new channel : make(chan val-type)
9+
send: channel <-
10+
receive: <- channel
11+
12+
- block:
13+
By default sends and receives block until both the sender and receiver are ready. This property allowed us to wait at the end of our program for the "ping" message without having to use any other synchronization.
14+
15+
*/
16+
17+
18+
import "fmt"
19+
20+
func main() {
21+
messages := make(chan string)
22+
23+
go func() { messages <- "ping" }()
24+
25+
msg := <-messages
26+
fmt.Println(msg)
27+
28+
msg_buffer := make(chan string, 2)
29+
msg_buffer <- "buffered"
30+
msg_buffer <- "channel"
31+
32+
fmt.Println(<-msg_buffer)
33+
fmt.Println(<-msg_buffer)
34+
35+
}

go/start.md

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)