TrunkCoupler<T> class sealed

Provides a dynamic connector that allows hotswapping or coldswapping the middle section of a Trunk (multi-node) pipeline at runtime.

Core Concept (Dynamic Topology Mutation): Just as CoralCoupler provides a dynamic socket for a single Coral node, TrunkCoupler provides a dynamic socket for a complex Trunk group. This allows you to replace an entire sub-graph of nodes with another sub-graph without breaking the downstream connections.

Common Use Cases:

  • Form Flow Changes: Swapping an entire group of input validation nodes when the user switches authentication methods (e.g., from Email to Phone).
  • Complex State Swapping: Replacing a complex dashboard data trunk with a different configuration dynamically.

Design Philosophy & Safety: Follows the identical lifecycle guarantees and garbage collection (Mooring) safety mechanisms as CoralCoupler.

AI & Developer Note: Swapping trunks during active execution requires hotswap: true to be set during initialization. Attempting to couple a trunk strongly owned by a non-detachable parent will throw a CoralNodeReleaseViolationException.

Example: Swapping Input Validation Trunks

// 1. Define two different trunk pipelines for inputs (assuming String values)
final emailTrunk = Trunk.of([emailCoral, passwordCoral]);
final phoneTrunk = Trunk.of([phoneCoral, smsCodeCoral]);

// 2. Create a trunk coupler starting with the email trunk
final authCoupler = TrunkCoupler<String>(emailTrunk, hotswap: true);

// 3. Build a downstream pipeline that aggregates the active trunk
final loginPipeline = authCoupler.aggregate((lines) {
  final id = lines.first.snapshot.data;
  final secret = lines.last.snapshot.data;
  return submitLogin(id, secret);
});

// 4. Later, swap to the phone authentication trunk dynamically
authCoupler.couple(phoneTrunk);
Implemented types
Available extensions

Constructors

TrunkCoupler(Trunk<T> inbound, {bool seal, bool hotswap})
Creates a TrunkCoupler with an initial inbound group.
factory
TrunkCoupler.late({bool seal, bool hotswap})
Creates a TrunkCoupler in a late/empty state.
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
isActivated bool
Whether the coupler and its downstream pipeline have been activated.
no setteroverride
isDeactivated bool
Whether the coupler has been permanently deactivated.
no setteroverride
isPaused bool
Whether the coupler is temporarily paused.
no setteroverride
isRunning bool
Whether the coupler is currently running and processing data.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
snapshot TrunkSnapshot<T>
Retrieves the most recent data snapshot from the currently coupled group.
no setter
trunk Trunk<T>
Exposes the underlying Trunk proxy group for downstream chaining.
no setteroverride

Methods

aggregate<T>(T aggregate(Iterable<Coral<S>> lines)) Coral<T>

Available on TrunkProvider<S>, provided by the TrunkProviderComputationExtension extension

combine() Coral<List<S>>

Available on TrunkProvider<S>, provided by the TrunkProviderComputationExtension extension

converge<T>(Coral<T> cascade(Iterable<Coral<S>> lines), {bool seal = true, bool hotswap = false, bool eager = false}) Coral<T>

Available on TrunkProvider<S>, provided by the TrunkProviderComputationExtension extension

couple(Trunk<T> newInbound) Trunk<T>?
Swaps the currently attached inbound source group with newInbound.
coupleGuarded(Trunk<T> callback()) Trunk<T>?
Safely swaps the inbound group using a callback.
decouple() → void
Immediately releases the currently attached inbound group.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
setError(Object error, [StackTrace? stackTrace]) Trunk<T>
Forcibly sets the coupler's state to damaged with the provided error.
toString() String
A string representation of this object.
inherited
toTerminal(void onDirty()) TrunkTerminal<T>

Available on TrunkProvider<T>, provided by the TrunkProviderExtension extension

tryDecoupling(CoralNode coralNode) bool
Attempts to decouple only if the currently attached inbound exactly matches coralNode.

Operators

operator ==(Object other) bool
The equality operator.
inherited