// Trigger this WindowEvent by calling all the registered callbacks in order of registration.
// TODO: should calling be exported?
429859
func (we *WindowEvent) Call(w *Window) {
	log.Finest("%s(%v)", wevNames[we], w.Id())
	for _, ev := range *we {
		ev(w)
	}
}
258114
func (s *LocalSupervisor) RegisterEventMapping(m EventMapping) {
	s.Lock()
	defer s.Unlock()

	s.eventMappings = append(s.eventMappings, m)
}
108918
func (f *FSM) afterEventCallbacks(e *Event) {
	if fn, ok := f.callbacks[cKey{e.Event, callbackAfterEvent}]; ok {
		fn(e)
	}
	if fn, ok := f.callbacks[cKey{"", callbackAfterEvent}]; ok {
		fn(e)
	}
}
867709
func (c *VirConnection) RegisterCloseCallback(cb CloseCallback, opaque func()) error {
	c.UnregisterCloseCallback()
	context := &closeContext{
		cb: cb,
		f:  opaque,
	}
	goCallbackId := registerCallbackId(context)
	callbackPtr := unsafe.Pointer(C.closeCallback_cgo)
	res := C.virConnectRegisterCloseCallback_cgo(c.ptr, C.virConnectCloseFunc(callbackPtr), C.long(goCallbackId))
	if res != 0 {
		freeCallbackId(goCallbackId)
		return GetLastError()
	}
	connData := getConnectionData(c)
	connData.closeCallbackId = &goCallbackId
	return nil
}
1164301
func NewCallbackEventListener(em event.EventMachine) *CallbackEventListener {
	return &CallbackEventListener{em: em, ids: []uint64{}}
}
938572
func (s *State) RegisterCallbacks(f ...Callback) {
	s.mu.Lock()
	defer s.mu.Unlock()

	s.callbacks = append(s.callbacks, f...)
}
735421
func (p *Parser) OnGameEvent(name string, fn GameEventHandler) {
	p.gameEventHandlers[name] = append(p.gameEventHandlers[name], fn)
}
124215
func (gs GlobalScope) Trigger(key int, data interface{}) error {
	if err := gs.EventScope.Trigger(key, data); err != nil {
		return err
	}
	for _, scope := range gs.scopes {
		if err := scope.Trigger(key, data); err != nil {
			return err
		}
	}
	return nil
}
1076589
func (c *EndpointsConfig) RegisterEventHandler(handler EndpointsHandler) {
	c.eventHandlers = append(c.eventHandlers, handler)
}
760377
func (s *Service) TriggerEventHandler(queryChat bool, bsonQuery map[string]interface{}, data interface{}) error {

	if s.EventHandler == nil {
		return fmt.Errorf("EventHandler missed for %s service", s.Name)
	}

	if bsonQuery == nil {
		return nil
	}

	db := mongoSession.Clone().DB(mongo.Database)
	defer db.Session.Close()

	ctx := &Context{db: db, ServiceName: s.Name}
	atLeastOneWasHandled := false

	if queryChat {
		chats, err := ctx.FindChats(bsonQuery)

		if err != nil {
			s.Log().WithError(err).Error("FindChats error")
		}
		for _, chat := range chats {
			if chat.Deactivated || chat.BotWasKickedOrStopped() {
				continue
			}
			ctx.Chat = chat.Chat
			err := s.EventHandler(ctx, data)

			if err != nil {
				ctx.Log().WithError(err).Error("EventHandler returned error")
			} else {
				atLeastOneWasHandled = true
			}
		}
	} else {
		users, err := ctx.FindUsers(bsonQuery)

		if err != nil {
			s.Log().WithError(err).Error("findUsers error")
		}

		for _, user := range users {
			ctx.User = user.User
			ctx.User.ctx = ctx
			ctx.Chat = Chat{ID: user.ID, ctx: ctx}
			err := s.EventHandler(ctx, data)

			if err != nil {
				ctx.Log().WithError(err).Error("EventHandler returned error")
			} else {
				atLeastOneWasHandled = true
			}
		}
	}

	if !atLeastOneWasHandled {
		return errors.New("No single chat was handled")
	}
	return nil
}
1094353
func (rlp *RateLimitPolicy) WindowBegin(windowEnd time.Time) time.Time {
	return windowEnd.Add(-1 * rlp.Window.Duration)
}
984996
func trigger(phase string, stack []plugin.Plugin, ctx *c.Context) *c.Context {
	var wg sync.WaitGroup
	wg.Add(1)

	// Finisher function
	done := func(_ctx *c.Context) {
		ctx = _ctx
		wg.Done()
	}

	i := len(stack)
	if i == 0 {
		wg.Done()
		return ctx
	}

	next := done
	for i > 0 {
		i--
		next = nextHandler(phase, stack[i], next, done)
	}

	// Exposes current middleware phase via context
	ctx.Set("$phase", phase)

	// Triggers the middleware call chain
	next(ctx)

	wg.Wait()
	return ctx
}
102806
func (m *rekeyFSM) listenOnEvent(
	event rekeyEventType, callback func(RekeyEvent), repeatedly bool) {
	m.muListeners.Lock()
	defer m.muListeners.Unlock()
	m.listeners[event] = append(m.listeners[event], rekeyFSMListener{
		onEvent:    callback,
		repeatedly: repeatedly,
	})
}
716705
func (c *Callbacks) OnCMsgClearWorldDecalsEvent(fn func(*dota.CMsgClearWorldDecalsEvent) error) {
	c.onCMsgClearWorldDecalsEvent = append(c.onCMsgClearWorldDecalsEvent, fn)
}
641883
func (c *Connect) RegisterCloseCallback(callback CloseCallback) error {
	c.UnregisterCloseCallback()
	goCallbackId := registerCallbackId(callback)
	var err C.virError
	res := C.virConnectRegisterCloseCallbackWrapper(c.ptr, C.long(goCallbackId), &err)
	if res != 0 {
		freeCallbackId(goCallbackId)
		return makeError(&err)
	}
	connData := getConnectionData(c)
	connData.closeCallbackId = &goCallbackId
	return nil
}
1297571
func (v *Stream) EventRemoveCallback() error {
	var err C.virError
	ret := C.virStreamEventRemoveCallbackWrapper(v.ptr, &err)
	if ret == -1 {
		return makeError(&err)
	}

	return nil
}
1238382
func OnReloaded(callback func()) {
	for _, pf := range onReloaded {
		if pf == &callback {
			return
		}
	}
	onReloaded = append(onReloaded, &callback)
}