Documentation
¶
Overview ¶
Package chord ports the parts of Pi's @earendil-works/chord application runtime that the durable packages consume: strict JSON copies and the publication-only replicated state attached to an authoritative source.
Chord's Context is context.Context. Listener deliveries that upstream runs from the microtask queue run on the goroutine that publishes the source frame; callers own any further scheduling.
Index ¶
- func CopyJSON(value any) (any, error)
- func CopyJSONObject(value map[string]any) (map[string]any, error)
- type AttachedReplicatedState
- func (state *AttachedReplicatedState[T]) Dispose()
- func (state *AttachedReplicatedState[T]) InternalSnapshot() (T, int)
- func (state *AttachedReplicatedState[T]) Subscribe(listener func(T, context.Context, ReplicatedStateDelivery)) (func(), error)
- func (state *AttachedReplicatedState[T]) SubscribeSource(listener SourceListener) func()
- func (state *AttachedReplicatedState[T]) Value() T
- type DeliveryKind
- type ReplicatedStateDelivery
- type ReplicatedStateInternals
- type ReplicatedStateSnapshot
- type ReplicatedStateSource
- type ReplicatedStateSourceAttachment
- type ReplicatedStateSourceFrame
- type ReplicatedStateSourceOptions
- type SourceListener
- type StateListener
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyJSON ¶
CopyJSON returns a detached copy of a strict JSON value: nil, bool, float64 (Go integer and float32 kinds are normalized), string, string-keyed maps, and slices. Non-finite numbers, cycles, and other Go kinds return a *delta.StrictJSONError. Go has no undefined, so upstream's omitUndefinedProperties option has no counterpart.
Types ¶
type AttachedReplicatedState ¶
type AttachedReplicatedState[T any] struct { // contains filtered or unexported fields }
AttachedReplicatedState is a synchronously hydrated publication-only state backed by one source attachment.
func AttachReplicatedStateSource ¶
func AttachReplicatedStateSource[T any](source ReplicatedStateSource[T], options ReplicatedStateSourceOptions) (*AttachedReplicatedState[T], error)
AttachReplicatedStateSource attaches a publication-only replicated state to one authoritative immutable source stream.
func (*AttachedReplicatedState[T]) Dispose ¶
func (state *AttachedReplicatedState[T]) Dispose()
Dispose idempotently releases the source attachment.
func (*AttachedReplicatedState[T]) InternalSnapshot ¶
func (state *AttachedReplicatedState[T]) InternalSnapshot() (T, int)
InternalSnapshot implements ReplicatedStateInternals.
func (*AttachedReplicatedState[T]) Subscribe ¶
func (state *AttachedReplicatedState[T]) Subscribe(listener func(T, context.Context, ReplicatedStateDelivery)) (func(), error)
Subscribe delivers the current value as a hydration, then every later update.
func (*AttachedReplicatedState[T]) SubscribeSource ¶
func (state *AttachedReplicatedState[T]) SubscribeSource(listener SourceListener) func()
SubscribeSource implements ReplicatedStateInternals.
func (*AttachedReplicatedState[T]) Value ¶
func (state *AttachedReplicatedState[T]) Value() T
Value returns the latest published immutable value; it stays readable after Dispose.
type DeliveryKind ¶
type DeliveryKind string
DeliveryKind is "hydrate" or "update".
const ( DeliveryHydrate DeliveryKind = "hydrate" DeliveryUpdate DeliveryKind = "update" )
type ReplicatedStateDelivery ¶
type ReplicatedStateDelivery struct {
Kind DeliveryKind
Sequence int
}
ReplicatedStateDelivery describes one listener delivery.
type ReplicatedStateInternals ¶
type ReplicatedStateInternals[T any] interface { // InternalSnapshot atomically captures the immutable value and its publication sequence. InternalSnapshot() (T, int) // SubscribeSource observes every published operation batch. SubscribeSource(listener SourceListener) func() }
ReplicatedStateInternals exposes a state's publication stream (upstream getReplicatedStateInternals).
type ReplicatedStateSnapshot ¶
ReplicatedStateSnapshot is the fixed immutable snapshot of an attachment.
type ReplicatedStateSource ¶
type ReplicatedStateSource[T any] interface { Attach() (ReplicatedStateSourceAttachment[T], error) }
ReplicatedStateSource is an authoritative immutable revision source.
type ReplicatedStateSourceAttachment ¶
type ReplicatedStateSourceAttachment[T any] interface { // Snapshot is captured at the atomic attachment boundary. Snapshot() ReplicatedStateSnapshot[T] // Activate installs the sole listener and drains every buffered frame in source commit order. Single use. Activate(listener func(frame ReplicatedStateSourceFrame[T])) error // Dispose stops delivery and releases source resources; idempotent. Dispose() }
ReplicatedStateSourceAttachment is one source subscription.
type ReplicatedStateSourceFrame ¶
type ReplicatedStateSourceFrame[T any] struct { // Cursor is monotonic; the first frame after a snapshot is snapshot cursor + 1. Cursor int // Value is the exact immutable value produced by this commit. Value T // Ops is the exact immutable batch that produced Value from the preceding revision. Ops []delta.Op Context context.Context }
ReplicatedStateSourceFrame is one committed frame of an authoritative source.
type ReplicatedStateSourceOptions ¶
type ReplicatedStateSourceOptions struct {
// OnError receives source-contract and listener failures; nil discards them after logging is impossible, matching
// upstream's asynchronous rethrow, which the host reports as an uncaught error.
OnError func(error)
}
ReplicatedStateSourceOptions configures an attached state.
type SourceListener ¶
SourceListener receives one published operation batch.
type StateListener ¶
type StateListener[T any] func(value T, ctx context.Context, delivery ReplicatedStateDelivery)
StateListener receives one delivery.