events

package
v2.22.27+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2021 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Copyright 2016 Wenhui Shen <www.webx.top>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddEvent

func AddEvent(eventName string, handler func(func(bool), ...interface{}))

添加事件

func DelEvent

func DelEvent(eventName string)

删除事件

func Event

func Event(eventName string, next func(bool), sessions ...interface{})

顺序执行事件

func GoEvent

func GoEvent(eventName string, next func(bool), sessions ...interface{})

并发执行事件

Types

type EventsInstance

type EventsInstance struct {
	// contains filtered or unexported fields
}
var Events *EventsInstance = NewEvents()

func NewEvents

func NewEvents() *EventsInstance

func (*EventsInstance) Delete

func (e *EventsInstance) Delete(eventName string)

func (*EventsInstance) Execute

func (e *EventsInstance) Execute(eventName string, next func(bool), sessions ...interface{})

*

  • 顺序执行事件

func (*EventsInstance) GoExecute

func (e *EventsInstance) GoExecute(eventName string, next func(bool), sessions ...interface{})

并发执行事件 [Examle 1:] Events.GoExecute("AfterHandler", func(_ bool) {//此匿名函数在本事件的最后执行

	session.Response.Send()
	session.Response.Close()
}, session)

[Examle 2:] Events.Execute("AfterResponse", func(_ bool) {}, session)

func (*EventsInstance) Register

func (e *EventsInstance) Register(eventName string, handler func(func(bool), ...interface{}))

注册事件 [Examle:]

Events.Register("AfterResponse", func(next func(bool),session ...interface{}) {
	log.Println("Got AfterResponse event!")
	isSuccess := true
	next(isSuccess) //这里的next函数无论什么情况下必须执行。
})

采用不同的方式执行事件时,此处的next函数的作用也是不同的: 1、在并发执行事件的时候,next函数的作用是通知程序我已经执行完了(不理会这一步是否执行成功); 2、在顺序执行事件的时候,next函数的作用是通知程序是否继续执行下一步,next(true)是继续执行下一步,next(false)是终止执行下一步

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL