Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. package main
  2.  
  3. func main() {
  4.  
  5. cp := 2
  6. ch := make(chan string, cp)
  7.  
  8. for i := 0; i < cp; i++ {
  9. go send(ch)
  10. }
  11. go send(ch)
  12.  
  13. for lc := range ch {
  14. print(lc)
  15.  
  16. }
  17.  
  18. }
  19.  
  20. func send(ch chan string) {
  21.  
  22. ch <- "hellon"
  23.  
  24. }
  25.  
  26. func send(c chan string, wg *sync.WaitGroup) {
  27. defer wg.Done()
  28. // ...
  29. }
  30.  
  31. wg := &sync.WaitGroup{}
  32.  
  33. for i := 0; i < cp; i++ {
  34. wg.Add(1)
  35. go send(ch, wg)
  36. }
  37. wg.Add(1)
  38. go send(ch, wg)
  39.  
  40. wg.Wait()
  41. close(ch)
  42.  
  43. for e := range(ch) {
  44. // ...
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement