Documentation ¶
Index ¶
- func Listen(name string, r func(Signal[any], any) error)
- func NewRecv[T any](cb func(Signal[T], T) error) *receiver[T]
- func Send(name string, value any) error
- type Error
- type Pool
- func (m *Pool[T]) CreateOrSend(name string, value T) error
- func (m *Pool[T]) Delete(signalName string)
- func (m *Pool[T]) Get(name string) Signal[T]
- func (m *Pool[T]) Listen(name string, r func(Signal[T], T) error) (Receiver[T], error)
- func (m *Pool[T]) Range(f func(value Signal[T]) bool)
- func (m *Pool[T]) Send(name string, value T) error
- func (m *Pool[T]) SendGlobal(value T) error
- type Receiver
- type Signal
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Listen ¶
Register a receiver to a signal.
This will register a receiver to a signal inside of the pool.
If the signal does not exist, it will be created.
This is a shorthand.
Types ¶
type Pool ¶
type Pool[T any] struct { // contains filtered or unexported fields }
Pool of signals.
Can be used to store, retrieve and delete signals.
Can also be used to send signals to receivers.
func (*Pool[T]) CreateOrSend ¶
Create or send a signal inside of the signal pool.
This will send a signal to the receivers, if the signal already exists.
func (*Pool[T]) Listen ¶
Register a receiver to a signal.
This will register a receiver to a signal inside of the pool.
If the signal does not exist, it will be created.
This is a shorthand.
func (*Pool[T]) Send ¶
Send a signal inside of the signal pool, from the signal with the given name to all receivers that are connected to the signal.
func (*Pool[T]) SendGlobal ¶
Send a signal globally, across all signals present in the pool.
This will send a signal to ALL receivers inside of this pool.
type Receiver ¶
type Receiver[T any] interface { // Receives the signal and value from the signal. Receive(Signal[T], T) error // Disconnects the receiver from the signal. Disconnect() error // Sets the signal on the receiver instance for later use. Signal(...Signal[T]) Signal[T] // Return the unique ID of the receiver. ID() uint64 }
Receiver interface This will be registered to any signals that it wants to receive. The receiver will be called when the signal is sent.
type Signal ¶
type Signal[T any] interface { // Return the name of the signal. Name() string // Send a message across the signal's receivers. Send(T) error // Send a message across the signal's receivers asynchronously. SendAsync(T) chan error // Connect a list of receivers to the signal. Connect(...Receiver[T]) error // Disconnect a list of receivers from a signal. Disconnect(...Receiver[T]) // Listen for a signal. Listen(func(Signal[T], T) error) (Receiver[T], error) // Clear all receivers for the signal. Clear() }
Signal interface.
Used for sending messages to receivers.