Created
February 23, 2016 16:20
-
-
Save gerep/091c623b0ab462bafe87 to your computer and use it in GitHub Desktop.
Using channels to return a unique number
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() { | |
| id := make(chan string) | |
| go func() { | |
| var counter int64 | |
| for { | |
| id <- fmt.Sprintf("%x", counter) | |
| counter++ | |
| } | |
| }() | |
| x := <-id | |
| fmt.Println(x) | |
| x = <-id | |
| fmt.Println(x) | |
| y := <-id | |
| fmt.Println(y) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment