Struct Recorder

Source
pub struct Recorder<T: Storage> { /* private fields */ }
Expand description

Persists records asynchronously.

You may want to use this instead of directly calling your persistence backend if you do not want to wait for the record to be persisted, in the handler which created the record. To achieve this Recoder spawns an actor to which all records are sent immediatly. The actor when uses the Storage trait to talk to your persistence backend.

Recorder takes ownership of an actor and the green thread it is running in.

Implementations§

Source§

impl<T> Recorder<T>
where T: Storage + 'static + Send, T::Record: Send, T::Query: Send,

Source

pub fn new(storage: T) -> Self

Constructs the recorder immediatly with a readily available storage backend. While this method is not blocking and returns control to the caller immediatly, it must still be run within the context of an async tokio runtime since it does spawn a tokio thread.

Source

pub fn from_delayed_storage( storage: impl Future<Output = T> + Send + 'static, ) -> Self

Constructs the recorder storage backend which will only be available ofter the future is resolved. The recorder will be availabel immediatly though, storing all calls to save within the message buffer. Use this contructor if you want your application to start up fast without waiting for the storage backend to have syncronized with the persisted state.

While this method is not blocking and returns control to the caller immediatly, it must still be run within the context of an async tokio runtime since it does spawn a tokio thread.

Source

pub fn save(&self, record: T::Record)

Sends the record to the internal actor for storage. This interface is fire and forget. It will not wait for the record to be actually persisted, just place it in the channel for the actor to pick up. This is why this method is both synchronous and non blocking.

Source

pub async fn close(self) -> T

Stop accepting new records to save, persist the ones send so far.

Gives back ownership of the underlying storage.

Source

pub async fn records(&self, query: T::Query) -> Vec<T::Record>

All the records stored in the internal storage.

Auto Trait Implementations§

§

impl<T> Freeze for Recorder<T>

§

impl<T> RefUnwindSafe for Recorder<T>

§

impl<T> Send for Recorder<T>
where T: Send, <T as Storage>::Record: Send, <T as Storage>::Query: Send,

§

impl<T> Sync for Recorder<T>
where T: Send, <T as Storage>::Record: Send, <T as Storage>::Query: Send,

§

impl<T> Unpin for Recorder<T>

§

impl<T> UnwindSafe for Recorder<T>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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, U> Into<U> for T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.