events

package
v0.0.0-...-5dd4785 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2020 License: Apache-2.0, BSD-2-Clause Imports: 2 Imported by: 45

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteCaller

func ByteCaller(handler interface{}, params ...interface{})

func ByteSliceCaller

func ByteSliceCaller(handler interface{}, params ...interface{})

func CallbackCaller

func CallbackCaller(handler interface{}, params ...interface{})

func ErrorCaller

func ErrorCaller(handler interface{}, params ...interface{})

func Int16Caller

func Int16Caller(handler interface{}, params ...interface{})

func Int16SliceCaller

func Int16SliceCaller(handler interface{}, params ...interface{})

func Int32Caller

func Int32Caller(handler interface{}, params ...interface{})

func Int32SliceCaller

func Int32SliceCaller(handler interface{}, params ...interface{})

func Int64Caller

func Int64Caller(handler interface{}, params ...interface{})

func Int64SliceCaller

func Int64SliceCaller(handler interface{}, params ...interface{})

func Int8Caller

func Int8Caller(handler interface{}, params ...interface{})

func Int8SliceCaller

func Int8SliceCaller(handler interface{}, params ...interface{})

func IntCaller

func IntCaller(handler interface{}, params ...interface{})

func IntSliceCaller

func IntSliceCaller(handler interface{}, params ...interface{})

func StringCaller

func StringCaller(handler interface{}, params ...interface{})

func StringSliceCaller

func StringSliceCaller(handler interface{}, params ...interface{})

func Uint16Caller

func Uint16Caller(handler interface{}, params ...interface{})

func Uint16SliceCaller

func Uint16SliceCaller(handler interface{}, params ...interface{})

func Uint32Caller

func Uint32Caller(handler interface{}, params ...interface{})

func Uint32SliceCaller

func Uint32SliceCaller(handler interface{}, params ...interface{})

func Uint64Caller

func Uint64Caller(handler interface{}, params ...interface{})

func Uint64SliceCaller

func Uint64SliceCaller(handler interface{}, params ...interface{})

func Uint8Caller

func Uint8Caller(handler interface{}, params ...interface{})

func Uint8SliceCaller

func Uint8SliceCaller(handler interface{}, params ...interface{})

Types

type Closure

type Closure struct {
	Id  uintptr
	Fnc interface{}
}

func NewClosure

func NewClosure(f interface{}) *Closure

type Event

type Event struct {
	// contains filtered or unexported fields
}
Example
// create event object (usually exposed through a public struct that holds all the different event types)
event := NewEvent(intStringCaller)

// we have to wrap a function in a closure to make it identifiable
closure1 := NewClosure(func(param1 int, param2 string) {
	fmt.Println("#1 " + param2 + ": " + strconv.Itoa(param1))
})

// multiple subscribers can attach to an event (closures can be inlined)
event.Attach(closure1)
event.Attach(NewClosure(func(param1 int, param2 string) {
	fmt.Println("#2 " + param2 + ": " + strconv.Itoa(param1))
}))

// trigger the event
event.Trigger(1, "Hello World")

// unsubscribe the first closure and trigger again
event.Detach(closure1)
event.Trigger(1, "Hello World")
Output:

#1 Hello World: 1
#2 Hello World: 1
#2 Hello World: 1

func NewEvent

func NewEvent(triggerFunc func(handler interface{}, params ...interface{})) *Event

func (*Event) Attach

func (ev *Event) Attach(closure *Closure)

func (*Event) Detach

func (ev *Event) Detach(closure *Closure)

func (*Event) DetachAll

func (ev *Event) DetachAll()

func (*Event) Trigger

func (ev *Event) Trigger(params ...interface{})

Jump to

Keyboard shortcuts

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