Signal

package
v0.0.0-...-ae8aae0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package Signal provides a type representing an event stream or pub/sub message queue.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Proxy

func Proxy[T API](signal Any, reuse func(T, complex128) bool, alloc func() (T, complex128)) (T, complex128)

Proxy can be used to transform the underlying encoding and implementation of an Any signal into a specific type. The alloc function should return a new implementation of the desired type, and the internal state. This may be cached in the existing implementation and, if so, will be passed to the check function so that it can decide whether to reuse the cache or not.

The uint64 can be used to avoid unnecessary allocations, such that T can be zero-sized if the implementation does not require more than 64bits of state.

Types

type API

type API interface {
	Attach(complex128, Callable.Function, Flags) error
	Remove(complex128, Callable.Function)
	Name(complex128) String.Readable
	Consumers(complex128) iter.Seq[Consumer]
	Emit(complex128, ...variant.Any)
	Emitter(complex128) variant.Any
}

type Any

type Any struct {
	// contains filtered or unexported fields
}

Any is a multi-producer, multi-consumer channel. Unlike with standard channels, consumers are not guaranteed to be running on a different goroutine, so emitting a signal may or may not be synchronous or asynchronous depending on the underlying API implementation. Any number of variant.Any values can be sent in a single send operation.

Also known as a Pub/Sub and/or message queue.

var Nil Any

Nil reference value, do not modify.

func Via

func Via(impl API, state complex128) Any

Via creates a new signal from the specified API implementation and state.

func (*Any) Attach

func (signal *Any) Attach(consumer Callable.Function, flags ...Flags) error

Attach connects this signal to the specified [Callable.Function] A signal can only be connected once to the same [Callable.Function]. If the signal is already connected, returns [Error.InvalidParameter]

func (Any) Consumers

func (signal Any) Consumers() iter.Seq[Consumer]

Consumers returns a sequence on all of the connected consumers.

func (Any) Emit

func (signal Any) Emit(values ...variant.Any)

Emit emits this signal. All consumers to this signal will be notified.

func (Any) Emitter

func (signal Any) Emitter() variant.Any

Emitter returns the originater associated with this signal.

func (Any) Has

func (signal Any) Has(fn Callable.Function) bool

Has returns true if the specified callable is connected to this signal.

func (Any) IsNull

func (signal Any) IsNull() bool

IsNull returns true if this signal is not connected to any callable.

func (Any) Name

func (signal Any) Name() String.Readable

Name returns the name of this signal.

func (*Any) Remove

func (signal *Any) Remove(consumer Callable.Function)

Remove the specified [Callable.Function] from this signal.

type Consumer

type Consumer struct {
	Callable Callable.Function `gd:"callable"`
	Flags    Flags             `gd:"flags"`
}

Consumer represents a connection between a signal and a callable.

type Flags

type Flags int
const (
	Deferred Flags = 1 << iota // the consumer will be notifed asynchronously.
	Persist                    // the consumer will be serialized.
	OneShot                    // the consumer will be removed after the first signal.
	Weak                       // the consumer can be garbage collected.
)

type Hexa

type Hexa[A, B, C, D, E, F any] struct {
	Any
}

Hexa of values that can be signaled, add this as a field inside a [classdb.Extension] to register it as a signal.

func (Hexa[A, B, C, D, E, F]) Emit

func (signal Hexa[A, B, C, D, E, F]) Emit(a A, b B, c C, d D, e E, f F)

Emit the pair of values to all connected signal handlers. Safe to call from any goroutine. This function is safe to call from any goroutine.

type Pair

type Pair[A, B any] struct {
	Any
}

Pair of values that can be signaled, add this as a field inside a [classdb.Extension] to register it as a signal.

func (Pair[A, B]) Emit

func (signal Pair[A, B]) Emit(a A, b B)

Emit the pair of values to all connected signal handlers. Safe to call from any goroutine.

type Quad

type Quad[A, B, C, D any] struct {
	Any
}

Quad of values that can be signaled, add this as a field inside a [classdb.Extension] to register it as a signal.

func (Quad[A, B, C, D]) Emit

func (signal Quad[A, B, C, D]) Emit(a A, b B, c C, d D)

Emit the pair of values to all connected signal handlers. Safe to call from any goroutine.

type Quin

type Quin[A, B, C, D, E any] struct {
	Any
}

Quin of values that can be signaled, add this as a field inside a [classdb.Extension] to register it as a signal.

func (Quin[A, B, C, D, E]) Emit

func (signal Quin[A, B, C, D, E]) Emit(a A, b B, c C, d D, e E)

Emit the pair of values to all connected signal handlers. Safe to call from any goroutine. This function is safe to call from any goroutine.

type Solo

type Solo[A any] struct {
	Any
}

Solo value that can be signaled, add this as a field inside a [classdb.Extension] to register it as a signal.

func (Solo[A]) Emit

func (signal Solo[A]) Emit(a A)

Emit the value to all connected signal handlers. Safe to call from any goroutine.

type Trio

type Trio[A, B, C any] struct {
	Any
}

Trio of values that can be signaled, add this as a field inside a [classdb.Extension] to register it as a signal.

func (Trio[A, B, C]) Emit

func (signal Trio[A, B, C]) Emit(a A, b B, c C)

Emit the pair of values to all connected signal handlers. Safe to call from any goroutine.

Jump to

Keyboard shortcuts

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