Documentation
¶
Overview ¶
Package events provides the internal event system.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidChannelType = fmt.Errorf("invalid channel type") ErrChannelAlreadyExists = fmt.Errorf("channel already exists") )
var (
ErrSubscribedToClosedChan = fmt.Errorf("cannot subscribe to a closed channel")
)
Functions ¶
Types ¶
type Channel ¶
type Channel[T any] interface { // Subscribe subscribes to the Channel, returning a channel by which events can // be read from, or an error should one occur (e.g. if this object is closed). // // This function is non-blocking unless the subscription-buffer is full. Subscribe() (Subscription[T], error) // Unsubscribe unsubscribes from the Channel, closing the provided channel. // // Will do nothing if this object is already closed. Unsubscribe(Subscription[T]) // Publish pushes the given item into this channel. Non-blocking. Publish(item T) // Close closes this Channel, and any owned or subscribing channels. Close() }
Channel represents a subscribable type that will expose inputted items to subscribers.
func New ¶
New creates and returns a new Channel instance.
At the moment this will always return a new simpleChannel, however that may change in the future as this feature gets fleshed out.
func NewSimpleChannel ¶
NewSimpleChannel creates a new simpleChannel with the given subscriberBufferSize and eventBufferSize.
Should the buffers be filled subsequent calls to functions on this object may start to block.
type Publisher ¶
type Publisher[T any] struct { // contains filtered or unexported fields }
Publisher hold a referance to the event channel, the associated subscription channel and the stream channel that returns data to the subscribed client
func NewPublisher ¶
NewPublisher creates a new Publisher with the given event Channel, subscribes to the event Channel and opens a new channel for the stream.
func (*Publisher[T]) Event ¶
func (p *Publisher[T]) Event() Subscription[T]
Event returns the subscription channel
func (*Publisher[T]) Publish ¶
Publish sends data to the streaming channel and unsubscribes if the client hangs for too long.
func (*Publisher[T]) Unsubscribe ¶
func (p *Publisher[T]) Unsubscribe()
Unsubscribe unsubscribes the client for the event channel and closes the stream.
type Subscription ¶
type Subscription[T any] chan T