Last active
January 28, 2016 14:11
-
-
Save nanoninja/a98e1c00ad8eee32b8cc to your computer and use it in GitHub Desktop.
Channel Example
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" | |
func main() { | |
ch := make(chan string) | |
go func(c chan string) { | |
ch <- "Hello Gopher" | |
}(ch) | |
fmt.Printf("%s", <-ch) | |
close(ch) | |
} |
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" | |
func main() { | |
ch := make(chan int) | |
go func() { | |
i := 0 | |
for { | |
ch <- i | |
i++ | |
} | |
}() | |
fmt.Printf("%d\n", <-ch) | |
fmt.Printf("%d\n", <-ch) | |
fmt.Printf("%d\n", <-ch) | |
fmt.Printf("%d\n", <-ch) | |
close(ch) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment