Created
March 22, 2020 09:32
-
-
Save dumindu/fddc1b0d4b6eff3e554ff40b52a6bb60 to your computer and use it in GitHub Desktop.
This file contains hidden or 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" | |
func main() { | |
ch := make(chan int) | |
go write(ch) | |
for v := range ch { | |
fmt.Println(v) | |
} | |
} | |
func write(ch chan int) { | |
for i := 1; i <= 10; i++ { | |
ch <- i | |
} | |
close(ch) // 💡 Close the channel to inform to the receiver, there are no more values coming | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment