SyncCycleChecker class
A thread-safe, Synchronized Circular Dependency Guard for asynchronous reactive flows.
SyncCycleChecker extends the cycle detection logic to handle propagation waves that span across asynchronous boundaries or multi-threaded execution contexts. It ensures that the "visited" state of the reactive graph remains consistent and protected from race conditions during concurrent pulse transmissions.
When to use
- Asynchronous Propagation: Use when a reactive wave spans across
asynchronous boundaries, such as
Futuretransformations or cross-isolate communication. - Multi-threaded Safety: Use in concurrent environments where multiple branches of the same pulse wave might be processed simultaneously.
- Topology Protection: Use to prevent infinite recursion in complex graphs that involve asynchronous nodes or deferred execution.
How it works
- Atomic Traversal: Wraps the underlying CycleChecker operations in a non-recursive Lock. This ensures that adding a node to the visited set is an atomic operation, preventing race conditions between concurrent branches of the same pulse.
- Conflict Detection: Before an asynchronous receptor processes a pulse, it invokes the add method. If the node was already visited within the current pulse wave, the operation is rejected.
- Coordination: Ensures that the "Visited" status is globally consistent across all concurrent tasks associated with a single Pulse lineage.
- Async Interface: Provides a Future-based API to align with the framework's non-blocking concurrency model.
Example
Future<void> asyncPropagate(Pulse pulse, Cell node) async {
// Access the synchronized checker for async flows
final isSafe = await pulse.checker.async.add(node);
if (!isSafe) {
print('Async cycle detected at $node; halting branch.');
return;
}
// Proceed with the asynchronous transformation
await node.processAsync(pulse);
}
See Also:
- CycleChecker: The high-performance synchronous variant.
- Lock: The underlying primitive used for synchronization.
- Pulse: The stimulus that carries this guard through the graph.
- Receptor: The primary consumer of this topology guard.
Constructors
- SyncCycleChecker(CycleChecker _checker)
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
add(
Cell cell) → Future< bool> - Atomically registers a node in the current asynchronous traversal path.
-
contains(
Cell cell) → Future< bool> - Atomically verifies if a specific node has already been traversed by the current asynchronous stimulus.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited