pub struct RawEventPool<T: Send + 'static> { /* private fields */ }Expand description
A pool of reusable thread-safe one-time events with manual pool lifecycle management.
§Examples
use events_once::RawEventPool;
let pool = Box::pin(RawEventPool::<String>::new());
for i in 0..3 {
// SAFETY: We promise the pool outlives both the returned endpoints.
let (tx, rx) = unsafe { pool.as_ref().rent() };
tx.send(format!("Message {i}"));
let message = rx.await.unwrap();
println!("{message}");
}Implementations§
Source§impl<T: Send + 'static> RawEventPool<T>
impl<T: Send + 'static> RawEventPool<T>
Sourcepub unsafe fn rent(
self: Pin<&Self>,
) -> (RawPooledSender<T>, RawPooledReceiver<T>)
pub unsafe fn rent( self: Pin<&Self>, ) -> (RawPooledSender<T>, RawPooledReceiver<T>)
Rents an event from the pool, returning its endpoints.
The event will be returned to the pool when both endpoints are dropped.
§Safety
The caller must guarantee that the pool outlives the endpoints.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if no events have currently been rented from the pool.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of events that have currently been rented from the pool.
Sourcepub fn inspect_awaiters(&self, f: impl FnMut(&Backtrace))
pub fn inspect_awaiters(&self, f: impl FnMut(&Backtrace))
Uses the provided closure to inspect the backtraces of the most recent awaiter of each awaited event in the pool.
This method is only available in debug builds (cfg(debug_assertions)).
For any data to be present, RUST_BACKTRACE=1 or RUST_LIB_BACKTRACE=1 must be set.
The closure is called once for each event in the pool that has been awaited at some point in the past.