// On adds a handler that's executed when an event happens.
349267
func (e *eventEmitter) On(ev EventType, h EventHandler) {
	e.addHandlerToMap(ev, h, e.listeners)
}
1159605
func (handler *Handler) Event(logEvent *event.Event) error {
	handler.channel <- logEvent
	return nil
}
472221
func (eh eventEventHandler) Handle(s *Session, i interface{}) {
	if t, ok := i.(*Event); ok {
		eh(s, t)
	}
}
1082215
func (o *object) On(eventName string, l Listener) {
	o.d.addListener(o.id, eventName, l)
}
272285
func (es *EventScope) On(eID int, callback app.EventCallback) {
	callbacks, ok := es.eventsCallbacks[eID]
	if !ok {
		es.eventsCallbacks[eID] = []app.EventCallback{callback}
		return
	}
	es.eventsCallbacks[eID] = append(callbacks, callback)
}
455347
func (l *RgbLedDriver) On() (err error) {
	if err = l.SetLevel(l.pinRed, l.redColor); err != nil {
		return
	}

	if err = l.SetLevel(l.pinGreen, l.greenColor); err != nil {
		return
	}

	if err = l.SetLevel(l.pinBlue, l.blueColor); err != nil {
		return
	}

	l.high = true
	return
}
817509
func (l *List) OnKeyEvent(ev KeyEvent) {
	if !l.IsFocused() {
		return
	}

	switch ev.Key {
	case KeyUp:
		l.moveUp()
	case KeyDown:
		l.moveDown()
	case KeyEnter:
		if l.onItemActivated != nil {
			l.onItemActivated(l)
		}
	}

	switch ev.Rune {
	case 'k':
		l.moveUp()
	case 'j':
		l.moveDown()
	}
}
837799
func (g *Group) OnStart() error {
	g.ticker = time.NewTicker(g.groupCheckDuration)
	go g.processTicks()
	return nil
}
893113
func (s *Server) Handle(method string, handlerFunc interface{}) {
	addHandler(s.handlers, method, handlerFunc)
}
1286985
func (l *LedDriver) On() (err error) {
	if err = l.connection.DigitalWrite(l.Pin(), 1); err != nil {
		return
	}
	l.high = true
	return
}
52093
func (ie *InitEvent) call() {
	log.Debug("OnInit callbacks executing")
	defer log.Debug("OnInit callbacks finished")
	for _, ev := range *ie {
		ev()
	}
}
789825
func (l *Logger) HandleEvent(ctx context.Context, event eh.Event) error {
	log.Println("event:", event)
	return nil
}
741055
func (m *MotorDriver) On() (err error) {
	if m.isDigital() {
		err = m.changeState(1)
	} else {
		if m.CurrentSpeed == 0 {
			m.CurrentSpeed = 255
		}
		err = m.Speed(m.CurrentSpeed)
	}
	return
}
679255
func (e *eventEmitter) OnChannel(ev EventType) chan Event {
	ch := make(chan Event, 1)
	e.On(ev, func(e Event) {
		ch <- e
	})

	return ch
}
918735
func (g *GoHttpServer) Event(event Event, args interface{}) (r EventResponse) {
	switch event {
	case ENGINE_STARTED:
		signal.Notify(g.signalChan, os.Interrupt, os.Kill)
		go func() {
			_ = <-g.signalChan
			serverLogger.Info("Received quit singal Please wait ... ")
			RaiseEvent(ENGINE_SHUTDOWN_REQUEST, nil)
		}()
	case ENGINE_SHUTDOWN_REQUEST:
		ctx, cancel := context.WithTimeout(context.Background(), time.Second*time.Duration(Config.IntDefault("app.cancel.timeout", 60)))
		defer cancel()
		g.Server.Shutdown(ctx)
	default:

	}

	return
}
196939
func (h *Handler) HandleEvent(e *events.Event) {
	buf := bufferPool.Get().(*buffer)
	buf.b = buf.b[:0]
	buf.b = append(buf.b, h.Prefix...)

	if fmt := h.TimeFormat; len(fmt) != 0 {
		loc := h.TimeLocation
		if loc == nil {
			loc = time.Local
		}
		buf.b = e.Time.In(loc).AppendFormat(buf.b, fmt)
		buf.b = append(buf.b, " - "...)
	}

	if len(e.Source) != 0 {
		buf.b = append(buf.b, e.Source...)
		buf.b = append(buf.b, " - "...)
	}

	buf.b = append(buf.b, e.Message...)
	buf.b = append(buf.b, '\n')

	if h.EnableArgs {
		hasError := false

		for _, a := range e.Args {
			if _, ok := a.Value.(error); ok {
				hasError = true
			} else {
				buf.b = append(buf.b, '\t')
				buf.b = append(buf.b, a.Name...)
				buf.b = append(buf.b, ':', ' ')
				fmt.Fprintf(buf, "%v\n", a.Value)
			}
		}

		if hasError {
			fmt.Fprint(buf, "\terrors:\n")

			for _, a := range e.Args {
				if err, ok := a.Value.(error); ok {
					fmt.Fprintf(buf, "\t\t- %+v\n", err)
				}
			}
		}
	}

	h.mutex.Lock()
	h.Output.Write(buf.b)
	h.mutex.Unlock()
	bufferPool.Put(buf)
}
466937
func (c *Channel) OnRead(f OnReadFunc) {
	// Create a new read handler for this channel.
	// Previous handlers are stopped first.
	handlerStopped := c.readHandler.New()

	// Start the handler goroutine.
	go func() {
		for {
			select {
			case data := <-c.readChan:
				// Call the callback in a new goroutine.
				go func() {
					// Recover panics and log the error.
					defer func() {
						if e := recover(); e != nil {
							log.L.Errorf("glue: panic while calling onRead function: %v\n%s", e, debug.Stack())
						}
					}()

					// Trigger the on read event function.
					f(data)
				}()
			case <-c.s.isClosedChan:
				// Release this goroutine if the socket is closed.
				return
			case <-handlerStopped:
				// Release this goroutine.
				return
			}
		}
	}()
}