Skip to content

Instantly share code, notes, and snippets.

@minhphong306
Created June 7, 2020 03:10
Show Gist options
  • Save minhphong306/b3208c577bbedb645acac1ced2732569 to your computer and use it in GitHub Desktop.
Save minhphong306/b3208c577bbedb645acac1ced2732569 to your computer and use it in GitHub Desktop.
colam_thimoi_coan_v3.go
package main
import (
"fmt"
)
// Cách 1: Move đoạn code đọc dữ liệu ra lên trước
func main() {
unbuffer := make(chan string)
go func() {
fmt.Println(<-unbuffer)
}()
unbuffer <- "Có làm thì mới có ăn"
}
// Cách 2: Wrap đoạn code đưa dữ liệu vào trong 1 goroutines
func main() {
unbuffer := make(chan string)
go func() {
unbuffer <- "Có làm thì mới có ăn"
}()
fmt.Println(<-unbuffer)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment