pub struct TickBarrier { /* private fields */ }Expand description
Barrier ensuring all shards complete a phase before any proceeds.
The tick barrier coordinates the phases within each simulation tick:
- Sense - agents sense the substrate (read-only phase)
- Act - process agent actions (write phase)
- Decay - decay signals, traces, and edges (maintenance phase)
- Advance - advance tick counter (finalization phase)
Each shard must signal completion of each phase, and all shards must complete before any can proceed to the next phase.
Implementations§
Source§impl TickBarrier
impl TickBarrier
Sourcepub fn new(shard_count: usize) -> Self
pub fn new(shard_count: usize) -> Self
Create a new tick barrier for the specified number of shards.
Sourcepub fn with_timeout(shard_count: usize, timeout_secs: u64) -> Self
pub fn with_timeout(shard_count: usize, timeout_secs: u64) -> Self
Create a tick barrier with custom timeout.
Sourcepub async fn set_shard_count(&self, count: usize)
pub async fn set_shard_count(&self, count: usize)
Update the expected shard count.
This should be called when shards are added or removed from the cluster.
Sourcepub async fn shard_count(&self) -> usize
pub async fn shard_count(&self) -> usize
Get the current shard count.
Sourcepub async fn complete(
&self,
shard_id: ShardId,
phase: TickPhase,
tick: Tick,
) -> DistributedResult<()>
pub async fn complete( &self, shard_id: ShardId, phase: TickPhase, tick: Tick, ) -> DistributedResult<()>
Mark a shard as having completed a phase.
§Arguments
shard_id- The shard that completedphase- The phase that was completedtick- The tick number
Sourcepub async fn is_complete(
&self,
shard_id: ShardId,
phase: TickPhase,
tick: Tick,
) -> bool
pub async fn is_complete( &self, shard_id: ShardId, phase: TickPhase, tick: Tick, ) -> bool
Check if a specific shard has completed a phase.
Sourcepub async fn completed_count(&self, phase: TickPhase, tick: Tick) -> usize
pub async fn completed_count(&self, phase: TickPhase, tick: Tick) -> usize
Get the number of shards that have completed a phase.
Sourcepub async fn wait_all(
&self,
phase: TickPhase,
tick: Tick,
) -> DistributedResult<()>
pub async fn wait_all( &self, phase: TickPhase, tick: Tick, ) -> DistributedResult<()>
Wait for all shards to complete a phase.
This will block until all registered shards have signaled completion of the specified phase, or until the timeout is reached.
§Arguments
phase- The phase to wait fortick- The tick number
§Errors
Returns DistributedError::PhaseTimeout if the timeout is reached
before all shards complete.
Sourcepub async fn wait_all_with_timeout(
&self,
phase: TickPhase,
tick: Tick,
timeout: Duration,
) -> DistributedResult<()>
pub async fn wait_all_with_timeout( &self, phase: TickPhase, tick: Tick, timeout: Duration, ) -> DistributedResult<()>
Wait for all shards with custom timeout.
Sourcepub async fn reset_for_tick(&self, _tick: Tick)
pub async fn reset_for_tick(&self, _tick: Tick)
Reset the barrier for a new tick.
This clears all completion records. Should be called before starting a new tick.