bridge

package module
v0.0.0-...-c4133e1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 5 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.

README

sink/bridge

Composes a crucible/state machine with a crucible/sink Manifold so every state transition fans out to all attached destinations, without either core importing the other.

m := sink.NewManifold(sink.WithTracer(tr)).Attach(dynamo.New(...), http.New(...))

machine := state.Forge[S, E, C]("order").
    Use(bridge.Middleware[S, E, C](m, bridge.WithTracer(tr))). // fan transitions out
    // ... states and transitions ...
    Quench(state.Strict())

machine.Cast(order).Fire(ctx, Submit) // the transition fans out through m

Two adapters:

  • Middleware wraps Fire. Because Fire carries a context.Context, the middleware starts a state.transition span and propagates its context into Manifold.Sink, so the sink.Sink span (and each outlet's span) nests under the transition span through the shared crucible/telemetry tracer. Use this when trace correlation matters.
  • Inspector adapts a Manifold to state's Inspector observer (wired with state.WithInspector). It is the one-line "fan everything out" path, but state.Inspector carries no context, so emit spans do not nest. See the note below.

A note on the observer seam

state.Inspector.Inspect(ev) takes no context.Context, so the ergonomic observer path cannot propagate trace context; correlation requires the Middleware seam. A minimal additive context-carrying inspector variant in crucible/state would let the observer path nest spans too; until then, Middleware is the trace-correlating bridge.

Stability

Experimental (pre-v1). The API may change until the suite locks v1.0.0.

License

Apache-2.0. See LICENSE and NOTICE.

Documentation

Overview

Package bridge composes a crucible/state machine with a crucible/sink Manifold without either core importing the other. It adapts state's two non-required observation seams to a sink fan-out:

  • Middleware wraps a machine's Fire so every successful transition fans out through a Manifold. Because Fire carries a context.Context, the middleware starts a "state.transition" span and propagates its context into Manifold.Sink, so the "sink.Sink" span (and each outlet's downstream span) nests under the transition span through the shared crucible/telemetry tracer. This is the context-propagating, trace-correlating path.
  • Inspector adapts a Manifold to state's Inspector observer. It is the ergonomic one-liner for "fan every transition out", but state.Inspector carries no context.Context, so it cannot propagate trace context; use Middleware when span nesting matters.

Stability

Experimental (pre-v1); the API may change until the suite locks v1.0.0.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Inspector

func Inspector(m *csink.Manifold) state.InspectorFunc

Inspector adapts m to a state.Inspector, fanning each transition event out through m. It uses context.Background because state.Inspector carries no context, so emit spans do not nest under a transition span; use Middleware for trace correlation. Register it with the WithInspector cast option.

func Middleware

func Middleware[S comparable, E comparable, C any](m *csink.Manifold, opts ...Option) state.Middleware[S, E, C]

Middleware returns a state.Middleware that fans every successful transition out through m. It starts a transition span on the configured tracer and propagates that span's context into m.Sink, so the emit span nests under the transition span. Install it with the machine builder's Use method.

Example
bucket := csink.NewBucket()
m := csink.NewManifold(csink.WithOutlets(bucket))

// Install the bridge as middleware: every transition fans out through m.
machine := state.ForgeFor[*bulb]("switch").
	Use(bridge.Middleware[string, string, *bulb](m)).
	State("off").State("on").
	Initial("off").
	CurrentStateFn(func(b *bulb) string { return b.cur() }).
	Transition("off").On("toggle").GoTo("on").
	Quench(state.Strict())

machine.Cast(&bulb{}).Fire(context.Background(), "toggle")

tr := csink.RecordsOf[bridge.Transition](bucket)[0]
fmt.Printf("%s: %s -> %s\n", tr.Event, tr.From, tr.To)
Output:
toggle: off -> on

Types

type Option

type Option func(*config)

Option configures the bridge adapters.

func WithSpanName

func WithSpanName(name string) Option

WithSpanName overrides the transition span name (default "state.transition").

func WithTracer

func WithTracer(t telemetry.Tracer) Option

WithTracer sets the tracer the Middleware starts the transition span on. The default is telemetry.NopTracer(). Wire the same tracer the Manifold uses so the emit span nests under the transition span. A nil tracer is ignored.

type Transition

type Transition struct {
	// Machine is the name of the machine that transitioned.
	Machine string
	// Event is the human-readable label of the event that drove the transition.
	Event string
	// From is the primary active leaf before the transition.
	From string
	// To is the primary active leaf after the transition.
	To string
}

Transition is the payload the bridge fans out for each observed state transition. Register a transformer for it on each destination's registry to persist or publish transitions.

Jump to

Keyboard shortcuts

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