Skip to main content

EventScope

Struct EventScope 

Source
pub struct EventScope { /* private fields */ }
Expand description

GC-like synchronization for event lifecycle tracking.

EventScope tracks in-flight events and allows callers to wait until all events within the scope have been fully processed.

§Thread Safety

EventScope is Clone, Send, and Sync. Cloning creates a new handle to the same underlying scope - all clones share the same counter.

§Timeout Behavior

The proven production timeout is 3 seconds (see DEFAULT_TIMEOUT). This is long enough to handle slow handlers while preventing deadlocks.

§Example

use reovim_kernel::api::v1::*;
use std::thread;
use std::time::Duration;

let scope = EventScope::new();
let scope2 = scope.clone(); // Same underlying scope

// Simulate async event processing
scope.increment();

let handle = thread::spawn(move || {
    thread::sleep(Duration::from_millis(10));
    scope2.decrement(); // Signal completion
});

// Wait for all events to complete
let completed = scope.wait_timeout(Duration::from_secs(1));
assert!(completed);

handle.join().unwrap();

Implementations§

Source§

impl EventScope

Source

pub fn new() -> Self

Create a new EventScope with counter initialized to 0.

The scope is considered complete when in_flight() == 0.

Source

pub fn id(&self) -> ScopeId

Get the unique ID of this scope.

Source

pub fn increment(&self)

Increment the in-flight counter.

Call this when emitting an event within the scope.

Source

pub fn decrement(&self)

Decrement the in-flight counter.

Call this when event dispatch completes. If the counter reaches 0, all waiters are notified.

§Panics

Panics in debug mode if called when counter is already 0.

Source

pub fn in_flight(&self) -> usize

Get the current in-flight count.

Source

pub fn is_complete(&self) -> bool

Check if the scope is complete (no in-flight events).

Source

pub fn wait(&self)

Block until the in-flight counter reaches 0.

If the counter is already 0, returns immediately.

§Warning

This can block indefinitely if events are never decremented. Prefer wait_timeout() in production code.

Source

pub fn wait_timeout(&self, timeout: Duration) -> bool

Block until the in-flight counter reaches 0, with timeout.

Returns true if the scope completed, false if the timeout elapsed.

§Example
use reovim_kernel::api::v1::*;
use std::time::Duration;

let scope = EventScope::new();

// Already complete - returns immediately
assert!(scope.wait_timeout(Duration::from_millis(100)));

// With in-flight event that never completes
scope.increment();
assert!(!scope.wait_timeout(Duration::from_millis(10)));
Source

pub fn wait_with_default_timeout(&self) -> bool

Block until complete, with default timeout and warning logging.

Uses DEFAULT_TIMEOUT (3 seconds). Returns true if completed, false if timed out.

In production, this logs a warning if the timeout is reached. For kernel-level code, we just return the result.

Trait Implementations§

Source§

impl Clone for EventScope

Source§

fn clone(&self) -> EventScope

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EventScope

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for EventScope

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.