fork download
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "time"
  6. )
  7.  
  8. type unique struct {
  9. id, nonce uint64
  10. }
  11.  
  12. func (unique *unique) print() {
  13. fmt.Println(unique.id)
  14. }
  15.  
  16. func main() {
  17. teste := []unique{unique{1, 2}, unique{3, 4}, unique{5, 6}}
  18. for _, valor := range teste {
  19. valorTmp := valor;
  20. go valorTmp.print()
  21. }
  22. time.Sleep(4 * time.Second)
  23. }
  24.  
  25. //https://pt.stackoverflow.com/q/215263/101
Success #stdin #stdout 0s 2980KB
stdin
Standard input is empty
stdout
1
3
5