memory

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package memory holds the in-memory adapters: a full implementation used by the test suite, and a template for custom adapters.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bus

type Bus struct {
	// contains filtered or unexported fields
}

Bus is a synchronous in-memory bus. Publishes are delivered to subscribers in order, on the publisher's goroutine.

func NewBus

func NewBus() *Bus

NewBus makes an empty Bus.

func (*Bus) Publish

func (b *Bus) Publish(_ context.Context, threadID string, event ports.AgentEvent) error

func (*Bus) Published

func (b *Bus) Published() []ports.AgentEvent

Published is every event ever published, in order.

func (*Bus) Subscribe

func (b *Bus) Subscribe(_ context.Context, threadID string, handler func(ports.AgentEvent)) (func() error, error)

func (*Bus) Subscribers

func (b *Bus) Subscribers(threadID string) int

Subscribers counts live subscriptions on a thread, so a test can prove a stream cleaned up after itself.

type Kv

type Kv struct {
	// contains filtered or unexported fields
}

Kv is an in-memory Kv for tests and local prototyping. Expiry is enforced lazily on read; Incr holds the lock, so concurrent callers can never collide on the same counter (§3.4).

func NewKv

func NewKv() *Kv

NewKv makes an empty Kv.

func (*Kv) Del

func (k *Kv) Del(_ context.Context, key string) error

func (*Kv) Get

func (k *Kv) Get(_ context.Context, key string) (string, bool, error)

func (*Kv) Incr

func (k *Kv) Incr(_ context.Context, key string) (int64, error)

func (*Kv) Set

func (k *Kv) Set(_ context.Context, key, value string, opts ports.SetOptions) (bool, error)

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

Queue is an in-memory queue with a Drain helper: tests process jobs exactly like the worker would.

func NewQueue

func NewQueue() *Queue

NewQueue makes an empty Queue.

func (*Queue) Delays

func (q *Queue) Delays() []time.Duration

Delays are the delivery delays requested per enqueue, index-aligned with Items.

func (*Queue) Drain

func (q *Queue) Drain(ctx context.Context, handler func(ctx context.Context, job ports.RunJob) error) (int, error)

Drain hands every waiting job to the handler, in order, including jobs the handler enqueues. Returns how many were handled.

func (*Queue) Enqueue

func (q *Queue) Enqueue(_ context.Context, job ports.RunJob, opts *ports.EnqueueOptions) error

func (*Queue) Items

func (q *Queue) Items() []ports.RunJob

Items are the jobs waiting, oldest first.

func (*Queue) Len

func (q *Queue) Len() int

Len is how many jobs wait.

func (*Queue) Shift

func (q *Queue) Shift() (ports.RunJob, bool)

Shift takes the oldest job, or false.

type Storage

type Storage struct {

	// LastContext is the StorageContext of the most recent call, so a test
	// can prove the run state reached the adapter (§2.10).
	LastContext ports.StorageContext
	// Contexts records every StorageContext seen, in order.
	Contexts []ports.StorageContext
	// contains filtered or unexported fields
}

Storage is a full in-memory Storage: tests, demos, and a template for custom adapters.

func NewStorage

func NewStorage() *Storage

NewStorage makes an empty Storage.

func (*Storage) Events

func (s *Storage) Events() ports.EventStore

func (*Storage) MessageRows

func (s *Storage) MessageRows(threadID string) []ports.MessageDTO

MessageRows is the raw message list for a thread, for tests.

func (*Storage) Messages

func (s *Storage) Messages() ports.MessageStore

func (*Storage) Threads

func (s *Storage) Threads() ports.ThreadStore

func (*Storage) Usage

func (s *Storage) Usage() ports.UsageStore

func (*Storage) UsageRows

func (s *Storage) UsageRows() []struct {
	ThreadID string
	ports.NewUsage
}

UsageRows is every recorded usage segment, for tests.

Jump to

Keyboard shortcuts

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