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(Arc::new(NoPersistence)));

BackgroundSync::new(&toggles).start().await;

Implementations§

source§

impl<F> BackgroundSync<F>

source

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.

source

pub fn interval(&mut self, value: Duration) -> &mut Self

source

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.

source

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.

source§

impl<F: Feattles + Sync + Send + 'static> BackgroundSync<F>

source

pub fn spawn(self) -> JoinHandle<()>

👎Deprecated: use start_sync() that will try a first update right away

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.

source

pub async fn start(self) -> Option<BoxError>

Start the sync operation by executing an update right now and then spawning a new tokio task.

This call will block until the first update returns. If it fails, the obtained error will be returned.

Note that the return type is Option<_> and not Result<_>, to avoid confusion: even if the first update fails, the sync process will continue in the background.

The tokio task will run by itself until the feattles instance gets dropped.

Operational logs are generated with the crate log.

Trait Implementations§

source§

impl<F: Debug> Debug for BackgroundSync<F>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more