Documentation
¶
Overview ¶
Package message exposes the generic Message type, used to represent a message in a system (e.g. Event, Command, etc.).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyIterated = errors.New("message.Stream: already iterated")
ErrAlreadyIterated is returned by Stream.Err when Iter is called more than once.
The second and subsequent iterations yield nothing; Err transitions to this sentinel value.
Functions ¶
This section is empty.
Types ¶
type Envelope ¶
Envelope bundles a Message to be exchanged with optional Metadata support.
func (Envelope[T]) ToGenericEnvelope ¶
func (e Envelope[T]) ToGenericEnvelope() GenericEnvelope
ToGenericEnvelope maps the Envelope instance into a GenericEnvelope one.
type GenericEnvelope ¶
GenericEnvelope is an Envelope type that can be used when the concrete Message type in the Envelope is not of interest.
type Message ¶
type Message interface {
Name() string
}
Message is a Message payload.
Each payload should have a unique name identifier, that can be used to uniquely route a message to its type.
type Metadata ¶
Metadata contains some data related to a Message that are not functional for the Message itself, but instead functioning as supporting information to provide additional context.
type Stream ¶ added in v0.4.1
type Stream[T any] struct { // contains filtered or unexported fields }
Stream is a single-use, iterator-backed sequence of values of type T.
Producers are written as callbacks that push values via yield and return a terminal error if the sequence cannot be completed. Consumers iterate via Stream.Iter and check Stream.Err at the end:
for v := range stream.Iter() {
// handle v
}
if err := stream.Err(); err != nil {
// handle failure
}
Consumer abandonment (break in the range loop) is NOT a failure; Err returns nil in that case.
Stream is single-use. Calling Stream.Iter more than once yields an empty sequence and sets Stream.Err to ErrAlreadyIterated.
Ctx cancellation is the producer's responsibility: producers should check ctx.Err() at loop boundaries and return it to signal cancellation.
func NewStream ¶ added in v0.4.1
NewStream returns a Stream backed by the given producer.
The producer is invoked lazily when Stream.Iter is called. It must push each value via yield and respect yield's bool return: if yield returns false, the producer should stop and return nil.
A non-nil error returned by the producer is captured and surfaced via Stream.Err.
func (*Stream[T]) Err ¶ added in v0.4.1
Err returns the terminal error of the stream, or nil if the stream completed without error (including the case of consumer abandonment).
Err is valid at any time; before Stream.Iter is called, Err returns nil.
func (*Stream[T]) Iter ¶ added in v0.4.1
Iter returns an iter.Seq over the stream's values.
Iter is single-use: calling it more than once returns an empty sequence and sets Stream.Err to ErrAlreadyIterated.