Struct feattle_sync::BackgroundSync
source · [−]pub struct BackgroundSync<F> { /* private fields */ }Expand description
Spawn a tokio task to poll Feattles::reload() continuously
A feattles instance will only ask the persistence layer for the current values when the
Feattles::reload() method is called. This type would do so regularly for you, until the
Feattles instance is dropped.
Example
use feattle_core::{feattles, Feattles};
use feattle_sync::BackgroundSync;
use feattle_core::persist::NoPersistence;
use std::sync::Arc;
feattles! {
struct MyToggles {
a: bool,
}
}
// `NoPersistence` here is just a mock for the sake of the example
let toggles = Arc::new(MyToggles::new(NoPersistence));
BackgroundSync::new(&toggles).spawn();Implementations
sourceimpl<F> BackgroundSync<F>
impl<F> BackgroundSync<F>
sourcepub fn new(feattles: &Arc<F>) -> Self
pub fn new(feattles: &Arc<F>) -> Self
Create a new poller for the given feattles instance. It will call Arc::downgrade() to
detect when the value is dropped.
sourcepub fn interval(&mut self, value: Duration) -> &mut Self
pub fn interval(&mut self, value: Duration) -> &mut Self
Set both Self::ok_interval and Self::err_interval
sourcepub fn ok_interval(&mut self, value: Duration) -> &mut Self
pub fn ok_interval(&mut self, value: Duration) -> &mut Self
After a successful reload, will wait for this long before starting the next one. By default this is 30 seconds.
sourcepub fn err_interval(&mut self, value: Duration) -> &mut Self
pub fn err_interval(&mut self, value: Duration) -> &mut Self
After a failed reload, will wait for this long before starting the next one. By default this is 60 seconds.
sourcepub fn spawn<P>(self) -> JoinHandle<()> where
F: Feattles<P> + Sync + Send + 'static,
P: Persist + Sync + 'static,
pub fn spawn<P>(self) -> JoinHandle<()> where
F: Feattles<P> + Sync + Send + 'static,
P: Persist + Sync + 'static,
Spawn a new tokio task, returning its handle. Usually you do not want to anything with the returned handle, since the task will run by itself until the feattles instance gets dropped.
Operational logs are generated with the crate log.
Trait Implementations
Auto Trait Implementations
impl<F> RefUnwindSafe for BackgroundSync<F> where
F: RefUnwindSafe,
impl<F> Send for BackgroundSync<F> where
F: Send + Sync,
impl<F> Sync for BackgroundSync<F> where
F: Send + Sync,
impl<F> Unpin for BackgroundSync<F>
impl<F> UnwindSafe for BackgroundSync<F> where
F: RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more