Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Lerp ¶
func Lerp[T constraints.Integer | constraints.Float](a, b T, ratio float64) T
Linearly interpolate between any two numbers of the same type using a ratio. The ratio is capped between 0 and 1
Types ¶
type Broker ¶ added in v0.3.0
type Broker[T any] struct { // contains filtered or unexported fields }
A data broker that can be published to, and any entity that has subscribed will get a copy of the message. Any subscriber should make sure to unsubscribe before deleting the reference. An independent go routine is started to receive published messages and to distribute them to all subscribers. The go routine stops once Stop() is called and all subscribers have unsubscribed. Ideally this is a 1-to-n communication system. If there are multiple publishers, it would be hard to know when to call Stop.
func (*Broker[T]) Publish ¶ added in v0.3.0
func (b *Broker[T]) Publish(msg T)
Send a message to every current subscriber.
func (*Broker[T]) Stop ¶ added in v0.3.0
func (b *Broker[T]) Stop()
Stop the data broker. Only call this once. All subscriptions will be closed
func (*Broker[T]) Subscribe ¶ added in v0.3.0
func (b *Broker[T]) Subscribe() chan T
Subscribe to the data broker. Messages can be received on the returned channel.
func (*Broker[T]) Unsubscribe ¶ added in v0.3.0
func (b *Broker[T]) Unsubscribe(msgCh chan T)
Unsubscribe from the data broker. The reference to the channel can be safely discarded after calling this.