// FlushAfter wraps the projection passed in and it calls
// the projection itself as new events come (as usual) in addition to calling
// the provided flush function periodically each time flush interval expires
FlushAfter wraps the projection passed in and it calls
the projection itself as new events come (as usual) in addition to calling
the provided flush function periodically each time flush interval expires
// FlushAfter wraps the projection passed in and it calls // the projection itself as new events come ( as usual ) in addition to calling // the provided flush function periodically each time flush interval expires
func FlushAfter(
	p Projection,
	flush func() error,
	flushInt time.Duration) Projection {
	work := make(chan EventData, 1)
	errors := make(chan error, 2)
	go func() {
		for {
			select {
			case <-time.After(flushInt):
				if err := flush(); err != nil {
					errors <- err
				}
			case w := <-work:
				if err := p(w); err != nil {
					errors <- err
				}
			}
		}
	}()
	return func(data EventData) error {
		select {
		case err := <-errors:
			return err
		default:
			work <- data
		}
		return nil
	}
}
func FlushAfter ( p Projection , flush func ( ) error , flushInt time . Duration ) Projection { work := make ( chan EventData , 1 ) errors := make ( chan error , 2 ) go func ( ) { for { select { case <- time . After ( flushInt ) : if err := flush ( ) ; err != nil { errors <- err } case w := <- work : if err := p ( w ) ; err != nil { errors <- err } } } } ( ) return func ( data EventData ) error { select { case err := <- errors : return err default : work <- data } return nil } }
FlushAfter wraps the projection passed in and it calls
the projection itself as new events come (as usual) in addition to calling
the provided flush function periodically each time flush interval expires
FlushAfter wraps the projection passed in and it calls the projection itself as new events come ( as usual ) in addition to calling the provided flush function periodically each time flush interval expires