pub struct Resurrectable<T, Err> { /* private fields */ }
Expand description
A wrapper around something async that will re-attempt initialization automatically
Implementations§
Source§impl<T, Err> Resurrectable<T, Err>where
Err: Debug,
impl<T, Err> Resurrectable<T, Err>where
Err: Debug,
Sourcepub async fn new<Fun: Fn() -> BoxFuture<'static, Result<T, Err>> + Send + Sync + 'static>(
initializer: Fun,
) -> Self
pub async fn new<Fun: Fn() -> BoxFuture<'static, Result<T, Err>> + Send + Sync + 'static>( initializer: Fun, ) -> Self
Construct a new resurrectable by passing a function that can instantiate the inner type.
If instantiation fails, the resurrectable will still be created, but the first call to
get
will re-run the initializer.
Sourcepub fn stub<Fun: Fn() -> BoxFuture<'static, Result<T, Err>> + Send + Sync + 'static>(
initializer: Fun,
) -> Self
pub fn stub<Fun: Fn() -> BoxFuture<'static, Result<T, Err>> + Send + Sync + 'static>( initializer: Fun, ) -> Self
Construct a new resurrectable by passing a function that can instantiate the inner type.
The function will not be called immediately. It will be called on the first call to get
Sourcepub async fn get(&self) -> Result<LockHolder<'_, T>, Err>
pub async fn get(&self) -> Result<LockHolder<'_, T>, Err>
Attempt to fetch the inner type the resurrectable holds. If it has not succesfully been initialized, this will attempt to initialize it first, returning an error if that fails.
Sourcepub async fn is_initted(&self) -> bool
pub async fn is_initted(&self) -> bool
Returns true if the wrapped type has been initialized. IE: If this returns false, the next
call to get
must run the initializer, otherwise not.
Auto Trait Implementations§
impl<T, Err> !Freeze for Resurrectable<T, Err>
impl<T, Err> !RefUnwindSafe for Resurrectable<T, Err>
impl<T, Err> Send for Resurrectable<T, Err>where
T: Send,
impl<T, Err> Sync for Resurrectable<T, Err>
impl<T, Err> Unpin for Resurrectable<T, Err>where
T: Unpin,
impl<T, Err> !UnwindSafe for Resurrectable<T, Err>
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request