Skip to content

Instantly share code, notes, and snippets.

@gerep
Created February 23, 2016 16:20
Show Gist options
  • Select an option

  • Save gerep/091c623b0ab462bafe87 to your computer and use it in GitHub Desktop.

Select an option

Save gerep/091c623b0ab462bafe87 to your computer and use it in GitHub Desktop.
Using channels to return a unique number
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