Add a util.Forever variant that ends on a stop channel

Integration tests that want to run controllers today are putting controllers into
infinite loops with go util.Forever.  util.Until will allow test cases to stop a controller
after a test ends
That assumes the channel is defined at the call site - my use case was a stop channel provided by the caller (ie a google context) where the caller wants the loop to stop at his convenience (and the channel might be passed to many goroutines).   I should have included an example before


> On Dec 2, 2014, at 2:17 PM, Daniel Smith <notifications@github.com> wrote:
> 
> In pkg/util/util.go:
> 
> > @@ -51,7 +51,19 @@ func HandleCrash() {
> >  
> >  // Forever loops forever running f every d.  Catches any panics, and keeps going.
> >  func Forever(f func(), period time.Duration) {
> > +	Until(f, period, nil)
> > +}
> > +
> > +// Until loops until stop channel is closed, running f every d.
> > +// Catches any panics, and keeps going. f may not be invoked if
> > +// stop channel is already closed.
> > +func Until(f func(), period time.Duration, stopCh <-chan struct{}) {
> Something like this should take care of it, no?
> 
> type stopper chan struct{}
> func (s stopper) Stop() { close(s) }
> 
> func Until(f func(), period time.Duration) stopper {
>   ...
>   ch := make(stopper)
>   ...
>   return ch
> }
> —
> Reply to this email directly or view it on GitHub.
>