timeline

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package timeline provides typed-event timeline replay: a sorted sequence of events at known offsets, advanced forward over an interval via a Cursor. Deterministic by construction — same input produces the same output emissions.

Domain-agnostic media-playback shape; common applications:

  • Animation systems (notify-state replay, keyframe events).
  • Video / audio editors (timeline-driven automation).
  • Music sequencers (note-on / note-off scheduling).
  • Scheduled-task playback / replay-driven simulations.
  • Any system that needs to replay a sequence of timed events exactly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cursor

type Cursor[E any] struct {
	// contains filtered or unexported fields
}

Cursor advances through a Timeline, emitting events whose offset falls within the most recently advanced span. The same shape as a media playback head — domain-agnostic.

func NewCursor

func NewCursor[E any](tl *Timeline[E]) *Cursor[E]

NewCursor returns a Cursor starting at offset 0.

func (*Cursor[E]) Advance

func (c *Cursor[E]) Advance(by time.Duration, fn func(ev Event[E]))

Advance moves the cursor by `by` and invokes fn for every event in (oldOffset, newOffset]. Events at the same offset emit in insertion order (stable sort).

func (*Cursor[E]) Offset

func (c *Cursor[E]) Offset() time.Duration

Offset returns the current cursor position along the timeline.

func (*Cursor[E]) Reset

func (c *Cursor[E]) Reset()

Reset returns the cursor to offset 0.

func (*Cursor[E]) Seek

func (c *Cursor[E]) Seek(to time.Duration, fn func(ev Event[E]))

Seek moves the cursor to `to`, emitting any events crossed since the previous position. Seeking backwards Resets and replays forward.

type Event

type Event[E any] struct {
	Offset  time.Duration
	Payload E
}

Event is a typed payload at a fixed offset from the timeline start.

type Timeline

type Timeline[E any] struct {
	// contains filtered or unexported fields
}

Timeline is an immutable, sorted sequence of Events.

func Merge

func Merge[E any](tls ...*Timeline[E]) *Timeline[E]

Merge combines two timelines into one preserving global order.

func New

func New[E any](events []Event[E]) *Timeline[E]

New constructs a Timeline. Events are sorted by Offset; the input slice is not mutated.

func (*Timeline[E]) Duration

func (t *Timeline[E]) Duration() time.Duration

Duration returns the offset of the last event (zero if empty).

func (*Timeline[E]) Events

func (t *Timeline[E]) Events() []Event[E]

Events returns a read-only snapshot of the timeline's events.

Jump to

Keyboard shortcuts

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