chord

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyJSON

func CopyJSON(value any) (any, error)

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.

func CopyJSONObject

func CopyJSONObject(value map[string]any) (map[string]any, error)

CopyJSONObject is CopyJSON for an object root.

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

type ReplicatedStateSnapshot[T any] struct {
	Value  T
	Cursor int
}

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

type SourceListener func(ops []delta.Op, sequence int, ctx context.Context)

SourceListener receives one published operation batch.

type StateListener

type StateListener[T any] func(value T, ctx context.Context, delivery ReplicatedStateDelivery)

StateListener receives one delivery.

Directories

Path Synopsis
Package delta produces immutable JSON revisions and exact operation batches for ordered replicas.
Package delta produces immutable JSON revisions and exact operation batches for ordered replicas.

Jump to

Keyboard shortcuts

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