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
impl EventScope
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new EventScope with counter initialized to 0.
The scope is considered complete when in_flight() == 0.
Sourcepub fn increment(&self)
pub fn increment(&self)
Increment the in-flight counter.
Call this when emitting an event within the scope.
Sourcepub fn decrement(&self)
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.
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Check if the scope is complete (no in-flight events).
Sourcepub fn wait(&self)
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.
Sourcepub fn wait_timeout(&self, timeout: Duration) -> bool
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)));Sourcepub fn wait_with_default_timeout(&self) -> bool
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
impl Clone for EventScope
Source§fn clone(&self) -> EventScope
fn clone(&self) -> EventScope
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more