//start initialize a forever-run go-routine ticker to check topics with events,
//ticker depends on the option of tickerInterval
start initialize a forever-run go-routine ticker to check topics with events,
ticker depends on the option of tickerInterval
// start initialize a forever - run go - routine ticker to check topics with events // ticker depends on the option of tickerInterval
func (d *localDispatcher) start(ctx context.Context) {
	ticker := time.NewTicker(d.options.TickerInterval)
	d.state.Swap(stateLocalRunning)
	go func() {
		for {
			select {
			case <-ticker.C:
				if d.state.Load() == stateLocalStopped {
					return
				}
				if d.state.Load() == stateLocalHandling {
					break
				}
				d.state.Store(stateLocalHandling)
				wg := &sync.WaitGroup{}
				wg.Add(len(d.events))
				for _, events := range d.events {
					go d.emit(ctx, events, wg)
				}
				wg.Wait()
				d.state.Store(stateLocalRunning)
			case events := <-d.changed:
				d.emit(ctx, events, nil)
			case <-ctx.Done():
				log.Println("local localDispatcher context done")
				return
			}
		}
	}()
}
func ( d * localDispatcher ) start ( ctx context . Context ) { ticker := time . NewTicker ( d . options . TickerInterval ) d . state . Swap ( stateLocalRunning ) go func ( ) { for { select { case <- ticker . C : if d . state . Load ( ) == stateLocalStopped { return } if d . state . Load ( ) == stateLocalHandling { break } d . state . Store ( stateLocalHandling ) wg := & sync . WaitGroup { } wg . Add ( len ( d . events ) ) for _ , events := range d . events { go d . emit ( ctx , events , wg ) } wg . Wait ( ) d . state . Store ( stateLocalRunning ) case events := <- d . changed : d . emit ( ctx , events , nil ) case <- ctx . Done ( ) : log . Println ( " " ) return } } } ( ) }
start initialize a forever-run go-routine ticker to check topics with events,
ticker depends on the option of tickerInterval
start initialize a forever - run go - routine ticker to check topics with events ticker depends on the option of tickerInterval
//if ticker is still handling, break select //polling the events with interval //new event dispatch