Created
June 7, 2020 03:10
-
-
Save minhphong306/b3208c577bbedb645acac1ced2732569 to your computer and use it in GitHub Desktop.
colam_thimoi_coan_v3.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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