periodic/periodic.go
func OnSignal(sig <-chan struct{}, procfunc gp.ProcessFunc) gp.Process {
	return gp.Go(func(proc gp.Process) {
		for {
			select {
			case <-sig:
				select {
				case <-proc.Go(procfunc).Closed(): // spin it out as a child, and wait till it's done.
				case <-proc.Closing(): // we're told to close
					return
				}
			case <-proc.Closing(): // we're told to close
				return
			}
		}
	})
}
func OnSignal(sig <-chan struct{}, procfunc gp.ProcessFunc) gp.Process {
	return gp.Go(func(proc gp.Process) {
		for {
			select {
			case <-sig:
				select {
				case <-proc.Go(procfunc).Closed(): // spin it out as a child, and wait till it's done.
				case <-proc.Closing(): // we're told to close
					return
				}
			case <-proc.Closing(): // we're told to close
				return
			}
		}
	})
}
func OnSignal ( sig <- chan struct { } , procfunc gp . ProcessFunc ) gp . Process { return gp . Go ( func ( proc gp . Process ) { for { select { case <- sig : select { case <- proc . Go ( procfunc ) . Closed ( ) : // spin it out as a child, and wait till it's done. case <- proc . Closing ( ) : // we're told to close return } case <- proc . Closing ( ) : // we're told to close return } } } ) }
// OnSignal calls the given ProcessFunc every time the signal fires, and waits for it to exit.
// This is sequentially rate limited, only one call will be in-flight at a time.
//
//  sig := make(chan struct{})
//  p := periodicproc.OnSignal(sig, func(proc goprocess.Process) {
//  	fmt.Println("fire!")
//  	<-time.After(time.Second) // delays sequential execution by 1 second
//  })
//
//  sig<- struct{}
//  sig<- struct{}
//  sig<- struct{}
//
//  // Output:
//  // fire!
//  // fire!
//  // fire!
OnSignal calls the given ProcessFunc every time the signal fires and waits for it to exit . This is sequentially rate limited only one call will be in - flight at a time . sig : = make ( chan struct {} ) p : = periodicproc . OnSignal ( sig func ( proc goprocess . Process ) { fmt . Println ( fire! ) < - time . After ( time . Second ) // delays sequential execution by 1 second } ) sig< - struct {} sig< - struct {} sig< - struct {} // Output : // fire! // fire! // fire!