pub struct LazySubsystem<T: Send + Sync + 'static> { /* private fields */ }Expand description
A lazily-initialized subsystem value.
The inner T is initialized on the first call to LazySubsystem::get
or LazySubsystem::get_or_try_init. Subsequent calls return the
cached value without re-running the initializer.
This is a thin, ergonomic wrapper around tokio::sync::OnceCell that
adds logging and a human-readable subsystem name.
Implementations§
Source§impl<T: Send + Sync + 'static> LazySubsystem<T>
impl<T: Send + Sync + 'static> LazySubsystem<T>
Sourcepub fn new(name: &'static str) -> Self
pub fn new(name: &'static str) -> Self
Create a new lazy subsystem with the given human-readable name.
Sourcepub async fn get<F, Fut>(&self, init: F) -> &T
pub async fn get<F, Fut>(&self, init: F) -> &T
Get the value, initializing it with init if necessary.
The init future runs at most once, even under concurrent access.
Sourcepub async fn get_or_try_init<F, Fut, E>(&self, init: F) -> Result<&T, E>
pub async fn get_or_try_init<F, Fut, E>(&self, init: F) -> Result<&T, E>
Get the value, initializing with a fallible init if necessary.
If init returns an error, the cell remains uninitialized and future
calls will retry.
Sourcepub fn is_initialized(&self) -> bool
pub fn is_initialized(&self) -> bool
Check whether the subsystem has been initialized.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for LazySubsystem<T>
impl<T> !RefUnwindSafe for LazySubsystem<T>
impl<T> Send for LazySubsystem<T>
impl<T> Sync for LazySubsystem<T>
impl<T> Unpin for LazySubsystem<T>
impl<T> UnsafeUnpin for LazySubsystem<T>
impl<T> !UnwindSafe for LazySubsystem<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more