enzogo

package module
v0.0.0-alpha.23 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2022 License: MIT Imports: 13 Imported by: 0

README

enzo

Documentation

Overview

Copy from https://github.com/chuckpreslar/emission/blob/7d2aae804ca2142c874751cba8f35425372c6ff4/emitter.go Package emission provides an event emitter.

Index

Constants

View Source
const (
	CloseMessage byte = 0x01

	PingMessage byte = 0x14
	PongMessage byte = 0x15

	PostMessage byte = 0x28
	BackMessage byte = 0x29
)

Variables

View Source
var ErrNoneFunction = errors.New("kind of Value for listener is not function")

Error presented when an invalid argument is provided as a listener function

Functions

func DefaultGenerateConnid

func DefaultGenerateConnid(r *http.Request) string

Types

type Context

type Context struct {
	Conn *websocket.Conn
	// contains filtered or unexported fields
}

func (*Context) Emit

func (ctx *Context) Emit(key string, data []byte, cb ...Handle) error

func (*Context) Error

func (ctx *Context) Error() error

func (*Context) GetConnid

func (ctx *Context) GetConnid() string

func (*Context) GetData

func (ctx *Context) GetData() []byte

func (*Context) GetHttpRequest

func (ctx *Context) GetHttpRequest() *http.Request

func (*Context) GetKey

func (ctx *Context) GetKey() string

func (*Context) GetPlugin

func (ctx *Context) GetPlugin(name string) Plugin

func (*Context) IsError

func (ctx *Context) IsError() bool

func (*Context) LongtimeEmit

func (ctx *Context) LongtimeEmit(key string, data []byte, cb ...Handle) error

func (*Context) Write

func (ctx *Context) Write(data []byte)

type Emitter

type Emitter struct {
	// Mutex to prevent race conditions within the Emitter.
	*sync.Mutex
	// contains filtered or unexported fields
}

Emitter ...

func (*Emitter) AddListener

func (emitter *Emitter) AddListener(event, listener interface{}) ListenerHandle

AddListener appends the listener argument to the event arguments slice in the Emitter's events map. If the number of listeners for an event is greater than the Emitter's maximum listeners then a warning is printed. If the reflect Value of the listener does not have a Kind of Func then AddListener panics. If a RecoveryListener has been set then it is called recovering from the panic.

func (*Emitter) Emit

func (emitter *Emitter) Emit(event interface{}, arguments ...interface{}) *Emitter

Emit attempts to use the reflect package to Call each listener stored in the Emitter's events map with the supplied arguments. Each listener is called within its own go routine. The reflect package will panic if the agruments supplied do not align the parameters of a listener function. If a RecoveryListener has been set then it is called after recovering from the panic.

func (*Emitter) EmitSync

func (emitter *Emitter) EmitSync(event interface{}, arguments ...interface{}) *Emitter

EmitSync attempts to use the reflect package to Call each listener stored in the Emitter's events map with the supplied arguments. Each listener is called synchronously. The reflect package will panic if the agruments supplied do not align the parameters of a listener function. If a RecoveryListener has been set then it is called after recovering from the panic.

func (*Emitter) GetListenerCount

func (emitter *Emitter) GetListenerCount(event interface{}) (count int)

GetListenerCount gets count of listeners for a given event.

func (*Emitter) Off

func (emitter *Emitter) Off(event, listener ListenerHandle)

Off is an alias for RemoveListener.

func (*Emitter) On

func (emitter *Emitter) On(event, listener interface{}) ListenerHandle

On is an alias for AddListener.

func (*Emitter) Once

func (emitter *Emitter) Once(event, listener interface{}) ListenerHandle

Once generates a new function which invokes the supplied listener only once before removing itself from the event's listener slice in the Emitter's events map. If the reflect Value of the listener does not have a Kind of Func then Once panics. If a RecoveryListener has been set then it is called after recovering from the panic.

func (*Emitter) RecoverWith

func (emitter *Emitter) RecoverWith(listener RecoveryListener) *Emitter

RecoverWith sets the listener to call when a panic occurs, recovering from panics and attempting to keep the application from crashing.

func (*Emitter) RemoveListener

func (emitter *Emitter) RemoveListener(event interface{}, listenerHandle ListenerHandle)

RemoveListener removes the listener argument from the event arguments slice in the Emitter's events map. If the reflect Value of the listener does not have a Kind of Func then RemoveListener panics. If a RecoveryListener has been set then it is called after recovering from the panic.

type Enzo

type Enzo struct {
	GenerateConnid func(r *http.Request) string
	// contains filtered or unexported fields
}

func New

func New() *Enzo

func (*Enzo) Off

func (enzo *Enzo) Off(key string) error

func (*Enzo) On

func (enzo *Enzo) On(key string, handle Handle) error

func (*Enzo) Once

func (enzo *Enzo) Once(key string, handle Handle) error

func (*Enzo) ServeHTTP

func (enzo *Enzo) ServeHTTP(rw http.ResponseWriter, r *http.Request)

func (*Enzo) Use

func (enzo *Enzo) Use(plugins ...Plugin)

type Handle

type Handle func(*Context)

type ListenerHandle

type ListenerHandle uint32

ListenerHandle is an opaque reference to a previously added listener. You need the handle to remove the listener.

type Plugin

type Plugin interface {
	Name() string
	Install(*Enzo)
}

type RecoveryListener

type RecoveryListener func(interface{}, interface{}, error)

RecoveryListener ...

Directories

Path Synopsis
examples
plugins

Jump to

Keyboard shortcuts

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