News for hackers. Stuff that matters.
Re:Go concurrency patterns by voidlogic on Thursday January 17, 2013 @01:02PM (#5073993)
There are many ways to deal with this, here is a simple one:

  ...
  ch := make(chan int)
  defer close(ch) //I can timeout later if I want
  go consumer(ch)
  ...
  //I timeout down here and return
  }
  
  func consumer(input chan int) { //I will terminate when the input channel is closed
  	for x := range input {
  		fmt.Printf("I got %d!\n", x)
  	}
  }

There are no comments on this comment yet.