Skip to main content

BatchGuard

Struct BatchGuard 

Source
pub struct BatchGuard<'a> { /* private fields */ }
Expand description

RAII guard returned by Core::begin_batch.

While alive, suppresses per-emit wave drains — multiple emit / complete / error / teardown / invalidate calls coalesce into one wave. On drop:

  • Outermost guard: drains the wave (fires sinks, runs cleanup, clears in-tick).
  • Nested guard (an outer BatchGuard or an in-progress wave already owns the in-tick flag): silently no-ops.

On thread panic during the closure body, the drop path discards pending tier-3+ delivery rather than firing sinks (avoids cascading panics). Subscribers observe no tier-3+ delivery for the panicked wave. State-node cache writes that already executed inside the closure are rolled back via wave-cache snapshots — cache_of(s) returns the pre- panic value. The atomicity guarantee covers both sink-observability and cache state.

§Thread safety

BatchGuard is !Send by design. begin_batch claims the one-Core-per-OS-thread in_tick ownership slot (D252) on the calling thread; sending the guard to another thread and dropping it there would clear in_tick against the wrong thread’s slot, breaking the “I own the wave scope” semantic. D246/S2c: single-owner ⇒ the §7 per-partition wave_owner re-entrant mutex(es) are deleted; !Send is now enforced solely by the PhantomData<*const ()> marker.

use graphrefly_core::{BatchGuard, BindingBoundary, Core, DepBatch, FnId, FnResult, HandleId, NodeId};
use std::sync::Arc;

struct Stub;
impl BindingBoundary for Stub {
    fn invoke_fn(&self, _: NodeId, _: FnId, _: &[DepBatch]) -> FnResult {
        FnResult::Noop { tracked: None }
    }
    fn custom_equals(&self, _: FnId, _: HandleId, _: HandleId) -> bool { false }
    fn release_handle(&self, _: HandleId) {}
}
fn requires_send<T: Send>(_: T) {}
let core = Core::new(Arc::new(Stub) as Arc<dyn BindingBoundary>);
let guard = core.begin_batch();
requires_send(guard); // <- compile_fail: BatchGuard is !Send.

Trait Implementations§

Source§

impl Drop for BatchGuard<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for BatchGuard<'a>

§

impl<'a> !RefUnwindSafe for BatchGuard<'a>

§

impl<'a> !Send for BatchGuard<'a>

§

impl<'a> !Sync for BatchGuard<'a>

§

impl<'a> Unpin for BatchGuard<'a>

§

impl<'a> UnsafeUnpin for BatchGuard<'a>

§

impl<'a> !UnwindSafe for BatchGuard<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.