gesignal

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

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

Go to latest
Published: May 14, 2024 License: MIT Imports: 0 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectOneShot

func ConnectOneShot[T any](event *Event[T], conn connection, slot func(T))

Types

type Event

type Event[T any] struct {
	// contains filtered or unexported fields
}

Event is a slot-signal container. It holds all currect event listeners and invokes their callbacks when the associated event is triggered. An event is triggered when Emit() method is called.

If you need 0 arguments callback, use Void type for the argument. If you need more than 1 argument in your callback, use tuple helper package. For example, a tuple.Value3[int, float, string] can be used to pass three arguments to your callback.

func (*Event[T]) Connect

func (e *Event[T]) Connect(conn connection, slot func(arg T))

Connect adds an event listener that will be called for every Emit called for this event. When connection is disposed, an associated callback will be unregistered. If this connection should be persistent, pass a nil value as conn. For a non-nil conn, it's possible to disconnect from event by using Disconnect method.

func (*Event[T]) Disconnect

func (e *Event[T]) Disconnect(conn connection)

Disconnect removes an event listener identified by this connection. Note that you can't disconnect a listener that was connected with nil connection object.

func (*Event[T]) Emit

func (e *Event[T]) Emit(arg T)

Emit triggers the associated event and calls all active callbacks with provided argument.

func (*Event[T]) IsEmpty

func (e *Event[T]) IsEmpty() bool

type Void

type Void struct{}

Void is a helper type that is recommended to be used instead of `struct{}`. You may want to use Void as the event type parameter when there is no useful data to be transmitted.

Jump to

Keyboard shortcuts

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